]> icculus.org git repositories - divverent/netradiant.git/blob - tools/quake3/q3map2/q3map2_fsr_newfiles/q3map2_fsr_svn158.patch
add a "todo item" directory containing VorteX's patches
[divverent/netradiant.git] / tools / quake3 / q3map2 / q3map2_fsr_newfiles / q3map2_fsr_svn158.patch
1 Index: brush.c\r
2 ===================================================================\r
3 --- brush.c     (revision 158)\r
4 +++ brush.c     (working copy)\r
5 @@ -78,7 +78,7 @@\r
6         
7         
8         /* count brushes */
9 -       for( brushes; brushes != NULL; brushes = brushes->next )
10 +       for( ; brushes != NULL; brushes = brushes->next )
11                 c++;
12         return c;
13  }
14 @@ -122,7 +122,7 @@\r
15         
16         
17         /* error check */
18 -       if( *((int*) b) == 0xFEFEFEFE )
19 +       if( *((unsigned int*) b) == 0xFEFEFEFE )
20         {
21                 Sys_FPrintf( SYS_VRB, "WARNING: Attempt to free an already freed brush!\n" );
22                 return;
23 @@ -135,7 +135,7 @@\r
24         
25         /* ydnar: overwrite it */
26         memset( b, 0xFE, (int) &(((brush_t*) 0)->sides[ b->numsides ]) );
27 -       *((int*) b) = 0xFEFEFEFE;
28 +       *((unsigned int*) b) = 0xFEFEFEFE;
29         
30         /* free it */
31         free( b );
32 @@ -156,7 +156,7 @@\r
33         
34         
35         /* walk brush list */
36 -       for( brushes; brushes != NULL; brushes = next )
37 +       for( ; brushes != NULL; brushes = next )
38         {
39                 next = brushes->next;
40                 FreeBrush( brushes );
41 Index: bsp.c\r
42 ===================================================================\r
43 --- bsp.c       (revision 158)\r
44 +++ bsp.c       (working copy)\r
45 @@ -194,7 +194,6 @@\r
46         char            level[ 2 ], shader[ 1024 ];
47         const char      *value;
48         
49 -       
50         /* sets integer blockSize from worldspawn "_blocksize" key if it exists */
51         value = ValueForKey( &entities[ 0 ], "_blocksize" );
52         if( value[ 0 ] == '\0' )
53 @@ -531,6 +530,9 @@\r
54         
55         /* write fogs */
56         EmitFogs();
57 +
58 +       /* vortex: emit meta stats */
59 +       EmitMetaStats();
60  }
61  
62  
63 Index: bspfile_abstract.c\r
64 ===================================================================\r
65 --- bspfile_abstract.c  (revision 158)\r
66 +++ bspfile_abstract.c  (working copy)\r
67 @@ -683,8 +683,26 @@\r
68         ep->value = copystring( value );
69  }
70  
71 +/*
72 +KeyExists()
73 +returns true if entity has this key
74 +*/
75  
76 +qboolean KeyExists( const entity_t *ent, const char *key )
77 +{
78 +       epair_t *ep;
79 +       
80 +       /* walk epair list */
81 +       for( ep = ent->epairs; ep != NULL; ep = ep->next )
82 +       {
83 +               if( !EPAIR_STRCMP( ep->key, key ) )
84 +                       return qtrue;
85 +       }
86  
87 +       /* no match */
88 +       return qfalse;
89 +}
90 +
91  /*
92  ValueForKey()
93  gets the value for an entity key
94 @@ -803,7 +821,6 @@\r
95  {
96         const char      *value;
97         
98 -       
99         /* get cast shadows */
100         if( castShadows != NULL )
101         {
102 @@ -831,5 +848,19 @@\r
103                 if( value[ 0 ] != '\0' )
104                         *recvShadows = atoi( value );
105         }
106 +
107 +       /* vortex: game-specific default eneity keys */
108 +       value = ValueForKey( ent, "classname" );
109 +       if (!Q_stricmp( game->magic, "dq" ) || !Q_stricmp( game->magic, "prophecy" ) )
110 +       {
111 +               /* vortex: deluxe quake default shadow flags */
112 +               if (!Q_stricmp( value, "func_wall" ) )
113 +               {
114 +                       if( recvShadows != NULL )
115 +                               *recvShadows = 1;
116 +                       if( castShadows != NULL )
117 +                               *castShadows = 1;
118 +               }
119 +       }
120  }
121  
122 Index: facebsp.c\r
123 ===================================================================\r
124 --- facebsp.c   (revision 158)\r
125 +++ facebsp.c   (working copy)\r
126 @@ -180,7 +180,7 @@\r
127         
128  
129         c = 0;
130 -       for( list; list != NULL; list = list->next )
131 +       for( ; list != NULL; list = list->next )
132                 c++;
133         return c;
134  }
135 Index: game_ef.h\r
136 ===================================================================\r
137 --- game_ef.h   (revision 158)\r
138 +++ game_ef.h   (working copy)\r
139 @@ -113,7 +113,16 @@\r
140         qfalse,                         /* wolf lighting model? */
141         128,                            /* lightmap width/height */
142         1.0f,                           /* lightmap gamma */
143 +       1.0f,                           /* lightmap exposure */
144         1.0f,                           /* lightmap compensate */
145 +       1.0f,                           /* lightgrid scale */
146 +       1.0f,                           /* lightgrid ambient scale */
147 +       qfalse,                         /* disable shader lightstyles hack */
148 +       qfalse,                         /* keep light entities on bsp */
149 +       8,                                      /* default patchMeta subdivisions tolerance */
150 +       qfalse,                         /* patch casting enabled */
151 +       qfalse,                         /* compile deluxemaps */
152 +       0,                                      /* deluxemaps default mode */
153         "IBSP",                         /* bsp file prefix */
154         46,                                     /* bsp file version */
155         qfalse,                         /* cod-style lump len/ofs order */
156 Index: game_etut.h\r
157 ===================================================================\r
158 --- game_etut.h (revision 158)\r
159 +++ game_etut.h (working copy)\r
160 @@ -148,7 +148,16 @@\r
161         qfalse,                         /* wolf lighting model? */
162         128,                            /* lightmap width/height */
163         2.2f,                           /* lightmap gamma */
164 +       1.0f,                           /* lightmap exposure */
165         1.0f,                           /* lightmap compensate */
166 +       1.0f,                           /* lightgrid scale */
167 +       1.0f,                           /* lightgrid ambient scale */
168 +       qfalse,                         /* disable shader lightstyles hack */
169 +       qfalse,                         /* keep light entities on bsp */
170 +       8,                                      /* default patchMeta subdivisions tolerance */
171 +       qfalse,                         /* patch casting enabled */
172 +       qfalse,                         /* compile deluxemaps */
173 +       0,                                      /* deluxemaps default mode */
174         "IBSP",                         /* bsp file prefix */
175         47,                                     /* bsp file version */
176         qfalse,                         /* cod-style lump len/ofs order */
177 Index: game_ja.h\r
178 ===================================================================\r
179 --- game_ja.h   (revision 158)\r
180 +++ game_ja.h   (working copy)\r
181 @@ -67,7 +67,16 @@\r
182         qfalse,                         /* wolf lighting model? */
183         128,                            /* lightmap width/height */
184         1.0f,                           /* lightmap gamma */
185 +       1.0f,                           /* lightmap exposure */
186         1.0f,                           /* lightmap compensate */
187 +       1.0f,                           /* lightgrid scale */
188 +       1.0f,                           /* lightgrid ambient scale */
189 +       qfalse,                         /* disable shader lightstyles hack */
190 +       qfalse,                         /* keep light entities on bsp */
191 +       8,                                      /* default patchMeta subdivisions tolerance */
192 +       qfalse,                         /* patch casting enabled */
193 +       qfalse,                         /* compile deluxemaps */
194 +       0,                                      /* deluxemaps default mode */
195         "RBSP",                         /* bsp file prefix */
196         1,                                      /* bsp file version */
197         qfalse,                         /* cod-style lump len/ofs order */
198 Index: game_jk2.h\r
199 ===================================================================\r
200 --- game_jk2.h  (revision 158)\r
201 +++ game_jk2.h  (working copy)\r
202 @@ -64,7 +64,16 @@\r
203         qfalse,                         /* wolf lighting model? */
204         128,                            /* lightmap width/height */
205         1.0f,                           /* lightmap gamma */
206 +       1.0f,                           /* lightmap exposure */
207         1.0f,                           /* lightmap compensate */
208 +       1.0f,                           /* lightgrid scale */
209 +       1.0f,                           /* lightgrid ambient scale */
210 +       qfalse,                         /* disable shader lightstyles hack */
211 +       qfalse,                         /* keep light entities on bsp */
212 +       8,                                      /* default patchMeta subdivisions tolerance */
213 +       qfalse,                         /* patch casting enabled */
214 +       qfalse,                         /* compile deluxemaps */
215 +       0,                                      /* deluxemaps default mode */
216         "RBSP",                         /* bsp file prefix */
217         1,                                      /* bsp file version */
218         qfalse,                         /* cod-style lump len/ofs order */
219 Index: game_qfusion.h\r
220 ===================================================================\r
221 --- game_qfusion.h      (revision 158)\r
222 +++ game_qfusion.h      (working copy)\r
223 @@ -1,195 +1,204 @@\r
224 -/* -------------------------------------------------------------------------------
225 -
226 -This code is based on source provided under the terms of the Id Software 
227 -LIMITED USE SOFTWARE LICENSE AGREEMENT, a copy of which is included with the
228 -GtkRadiant sources (see LICENSE_ID). If you did not receive a copy of 
229 -LICENSE_ID, please contact Id Software immediately at info@idsoftware.com.
230 -
231 -All changes and additions to the original source which have been developed by
232 -other contributors (see CONTRIBUTORS) are provided under the terms of the
233 -license the contributors choose (see LICENSE), to the extent permitted by the
234 -LICENSE_ID. If you did not receive a copy of the contributor license,
235 -please contact the GtkRadiant maintainers at info@gtkradiant.com immediately.
236 -
237 -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
238 -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
239 -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
240 -DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
241 -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
242 -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
243 -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
244 -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245 -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
246 -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
247 -
248 -----------------------------------------------------------------------------------
249 -
250 -This code has been altered significantly from its original form, to support
251 -several games based on the Quake III Arena engine, in the form of "Q3Map2."
252 -
253 -------------------------------------------------------------------------------- */
254 -
255 -
256 -
257 -/* marker */
258 -#ifndef GAME_QFUSION_H
259 -#define GAME_QFUSION_H
260 -
261 -
262 -
263 -/* -------------------------------------------------------------------------------
264 -
265 -content and surface flags
266 -
267 -------------------------------------------------------------------------------- */
268 -
269 -/* game flags */
270 -#define F_CONT_SOLID                           1                       /* an eye is never valid in a solid */
271 -#define F_CONT_LAVA                                    8
272 -#define F_CONT_SLIME                           16
273 -#define F_CONT_WATER                           32
274 -#define F_CONT_FOG                                     64
275 -
276 -#define F_CONT_AREAPORTAL                      0x8000
277 -
278 -#define F_CONT_PLAYERCLIP                      0x10000
279 -#define F_CONT_MONSTERCLIP                     0x20000
280 -#define F_CONT_TELEPORTER                      0x40000
281 -#define F_CONT_JUMPPAD                         0x80000
282 -#define F_CONT_CLUSTERPORTAL           0x100000
283 -#define F_CONT_DONOTENTER                      0x200000
284 -#define F_CONT_BOTCLIP                         0x400000
285 -
286 -#define F_CONT_ORIGIN                          0x1000000       /* removed before bsping an entity */
287 -
288 -#define F_CONT_BODY                                    0x2000000       /* should never be on a brush, only in game */
289 -#define F_CONT_CORPSE                          0x4000000
290 -#define F_CONT_DETAIL                          0x8000000       /* brushes not used for the bsp */
291 -#define F_CONT_STRUCTURAL                      0x10000000      /* brushes used for the bsp */
292 -#define F_CONT_TRANSLUCENT                     0x20000000      /* don't consume surface fragments inside */
293 -#define F_CONT_TRIGGER                         0x40000000
294 -#define F_CONT_NODROP                          0x80000000      /* don't leave bodies or items (death fog, lava) */
295 -
296 -#define F_SURF_NODAMAGE                                0x1                     /* never give falling damage */
297 -#define F_SURF_SLICK                           0x2                     /* effects game physics */
298 -#define F_SURF_SKY                                     0x4                     /* lighting from environment map */
299 -#define F_SURF_LADDER                          0x8
300 -#define F_SURF_NOIMPACT                                0x10            /* don't make missile explosions */
301 -#define F_SURF_NOMARKS                         0x20            /* don't leave missile marks */
302 -#define F_SURF_FLESH                           0x40            /* make flesh sounds and effects */
303 -#define F_SURF_NODRAW                          0x80            /* don't generate a drawsurface at all */
304 -#define F_SURF_HINT                                    0x100           /* make a primary bsp splitter */
305 -#define F_SURF_SKIP                                    0x200           /* completely ignore, allowing non-closed brushes */
306 -#define F_SURF_NOLIGHTMAP                      0x400           /* surface doesn't need a lightmap */
307 -#define F_SURF_POINTLIGHT                      0x800           /* generate lighting info at vertexes */
308 -#define F_SURF_METALSTEPS                      0x1000          /* clanking footsteps */
309 -#define F_SURF_NOSTEPS                         0x2000          /* no footstep sounds */
310 -#define F_SURF_NONSOLID                                0x4000          /* don't collide against curves with this set */
311 -#define F_SURF_LIGHTFILTER                     0x8000          /* act as a light filter during q3map -light */
312 -#define F_SURF_ALPHASHADOW                     0x10000         /* do per-pixel light shadow casting in q3map */
313 -#define F_SURF_NODLIGHT                                0x20000         /* don't dlight even if solid (solid lava, skies) */
314 -#define F_SURF_DUST                                    0x40000         /* leave a dust trail when walking on this surface */
315 -
316 -/* ydnar flags */
317 -#define F_SURF_VERTEXLIT                       (F_SURF_POINTLIGHT | F_SURF_NOLIGHTMAP)
318 -
319 -
320 -
321 -/* -------------------------------------------------------------------------------
322 -
323 -game_t struct
324 -
325 -------------------------------------------------------------------------------- */
326 -
327 -{
328 -       "qfusion",                      /* -game x */
329 -       "baseq3",                       /* default base game data dir */
330 -       ".q3a",                         /* unix home sub-dir */
331 -       "quake",                        /* magic path word */
332 -       "scripts",                      /* shader directory */
333 -       2048,                           /* max lightmapped surface verts */
334 -       2048,                           /* max surface verts */
335 -       12288,                          /* max surface indexes */
336 -       qtrue,                          /* flares */
337 -       "flareshader",          /* default flare shader */
338 -       qfalse,                         /* wolf lighting model? */
339 -       512,                            /* lightmap width/height */
340 -       1.0f,                           /* lightmap gamma */
341 -       1.0f,                           /* lightmap compensate */
342 -       "FBSP",                         /* bsp file prefix */
343 -       1,                                      /* bsp file version */
344 -       qfalse,                         /* cod-style lump len/ofs order */
345 -       LoadRBSPFile,           /* bsp load function */
346 -       WriteRBSPFile,          /* bsp write function */
347 -
348 -       {
349 -               /* name                         contentFlags                            contentFlagsClear                       surfaceFlags                            surfaceFlagsClear                       compileFlags                            compileFlagsClear */
350 -               
351 -               /* default */
352 -               { "default",            F_CONT_SOLID,                           -1,                                                     0,                                                      -1,                                                     C_SOLID,                                        -1 },
353 -               
354 -               
355 -               /* ydnar */
356 -               { "lightgrid",          0,                                                      0,                                                      0,                                                      0,                                                      C_LIGHTGRID,                            0 },
357 -               { "antiportal",         0,                                                      0,                                                      0,                                                      0,                                                      C_ANTIPORTAL,                           0 },
358 -               { "skip",                       0,                                                      0,                                                      0,                                                      0,                                                      C_SKIP,                                         0 },
359 -               
360 -               
361 -               /* compiler */
362 -               { "origin",                     F_CONT_ORIGIN,                          F_CONT_SOLID,                           0,                                                      0,                                                      C_ORIGIN | C_TRANSLUCENT,       C_SOLID },
363 -               { "areaportal",         F_CONT_AREAPORTAL,                      F_CONT_SOLID,                           0,                                                      0,                                                      C_AREAPORTAL | C_TRANSLUCENT,   C_SOLID },
364 -               { "trans",                      F_CONT_TRANSLUCENT,                     0,                                                      0,                                                      0,                                                      C_TRANSLUCENT,                          0 },
365 -               { "detail",                     F_CONT_DETAIL,                          0,                                                      0,                                                      0,                                                      C_DETAIL,                                       0 },
366 -               { "structural",         F_CONT_STRUCTURAL,                      0,                                                      0,                                                      0,                                                      C_STRUCTURAL,                           0 },
367 -               { "hint",                       0,                                                      0,                                                      F_SURF_HINT,                            0,                                                      C_HINT,                                         0 },
368 -               { "nodraw",                     0,                                                      0,                                                      F_SURF_NODRAW,                          0,                                                      C_NODRAW,                                       0 },
369 -               
370 -               { "alphashadow",        0,                                                      0,                                                      F_SURF_ALPHASHADOW,                     0,                                                      C_ALPHASHADOW | C_TRANSLUCENT,  0 },
371 -               { "lightfilter",        0,                                                      0,                                                      F_SURF_LIGHTFILTER,                     0,                                                      C_LIGHTFILTER | C_TRANSLUCENT,  0 },
372 -               { "nolightmap",         0,                                                      0,                                                      F_SURF_VERTEXLIT,                       0,                                                      C_VERTEXLIT,                            0 },
373 -               { "pointlight",         0,                                                      0,                                                      F_SURF_VERTEXLIT,                       0,                                                      C_VERTEXLIT,                            0 },
374 -               
375 -               
376 -               /* game */
377 -               { "nonsolid",           0,                                                      F_CONT_SOLID,                           F_SURF_NONSOLID,                        0,                                                      0,                                                      C_SOLID },
378 -               
379 -               { "trigger",            F_CONT_TRIGGER,                         F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
380 -               
381 -               { "water",                      F_CONT_WATER,                           F_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },
382 -               { "slime",                      F_CONT_SLIME,                           F_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },
383 -               { "lava",                       F_CONT_LAVA,                            F_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },
384 -               
385 -               { "playerclip",         F_CONT_PLAYERCLIP,                      F_CONT_SOLID,                           0,                                                      0,                                                      C_DETAIL | C_TRANSLUCENT,       C_SOLID },
386 -               { "monsterclip",        F_CONT_MONSTERCLIP,                     F_CONT_SOLID,                           0,                                                      0,                                                      C_DETAIL | C_TRANSLUCENT,       C_SOLID },
387 -               { "nodrop",                     F_CONT_NODROP,                          F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
388 -               
389 -               { "clusterportal",      F_CONT_CLUSTERPORTAL,           F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
390 -               { "donotenter",         F_CONT_DONOTENTER,                      F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
391 -               { "botclip",            F_CONT_BOTCLIP,                         F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
392 -               
393 -               { "fog",                        F_CONT_FOG,                                     F_CONT_SOLID,                           0,                                                      0,                                                      C_FOG,                                          C_SOLID },
394 -               { "sky",                        0,                                                      0,                                                      F_SURF_SKY,                                     0,                                                      C_SKY,                                          0 },
395 -               
396 -               { "slick",                      0,                                                      0,                                                      F_SURF_SLICK,                           0,                                                      0,                                                      0 },
397 -               
398 -               { "noimpact",           0,                                                      0,                                                      F_SURF_NOIMPACT,                        0,                                                      0,                                                      0 },
399 -               { "nomarks",            0,                                                      0,                                                      F_SURF_NOMARKS,                         0,                                                      C_NOMARKS,                                      0 },
400 -               { "ladder",                     0,                                                      0,                                                      F_SURF_LADDER,                          0,                                                      0,                                                      0 },
401 -               { "nodamage",           0,                                                      0,                                                      F_SURF_NODAMAGE,                        0,                                                      0,                                                      0 },
402 -               { "metalsteps",         0,                                                      0,                                                      F_SURF_METALSTEPS,                      0,                                                      0,                                                      0 },
403 -               { "flesh",                      0,                                                      0,                                                      F_SURF_FLESH,                           0,                                                      0,                                                      0 },
404 -               { "nosteps",            0,                                                      0,                                                      F_SURF_NOSTEPS,                         0,                                                      0,                                                      0 },
405 -               { "nodlight",           0,                                                      0,                                                      F_SURF_NODLIGHT,                        0,                                                      0,                                                      0 },
406 -               { "dust",                       0,                                                      0,                                                      F_SURF_DUST,                            0,                                                      0,                                                      0 },
407 -               
408 -               
409 -               /* null */
410 -               { NULL, 0, 0, 0, 0, 0, 0 }
411 -       }
412 -}
413 -
414 -
415 -
416 -/* end marker */
417 -#endif
418 -
419 +/* -------------------------------------------------------------------------------\r
420 +\r
421 +This code is based on source provided under the terms of the Id Software \r
422 +LIMITED USE SOFTWARE LICENSE AGREEMENT, a copy of which is included with the\r
423 +GtkRadiant sources (see LICENSE_ID). If you did not receive a copy of \r
424 +LICENSE_ID, please contact Id Software immediately at info@idsoftware.com.\r
425 +\r
426 +All changes and additions to the original source which have been developed by\r
427 +other contributors (see CONTRIBUTORS) are provided under the terms of the\r
428 +license the contributors choose (see LICENSE), to the extent permitted by the\r
429 +LICENSE_ID. If you did not receive a copy of the contributor license,\r
430 +please contact the GtkRadiant maintainers at info@gtkradiant.com immediately.\r
431 +\r
432 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''\r
433 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
434 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
435 +DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY\r
436 +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
437 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
438 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\r
439 +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
440 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
441 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
442 +\r
443 +----------------------------------------------------------------------------------\r
444 +\r
445 +This code has been altered significantly from its original form, to support\r
446 +several games based on the Quake III Arena engine, in the form of "Q3Map2."\r
447 +\r
448 +------------------------------------------------------------------------------- */\r
449 +\r
450 +\r
451 +\r
452 +/* marker */\r
453 +#ifndef GAME_QFUSION_H\r
454 +#define GAME_QFUSION_H\r
455 +\r
456 +\r
457 +\r
458 +/* -------------------------------------------------------------------------------\r
459 +\r
460 +content and surface flags\r
461 +\r
462 +------------------------------------------------------------------------------- */\r
463 +\r
464 +/* game flags */\r
465 +#define F_CONT_SOLID                           1                       /* an eye is never valid in a solid */\r
466 +#define F_CONT_LAVA                                    8\r
467 +#define F_CONT_SLIME                           16\r
468 +#define F_CONT_WATER                           32\r
469 +#define F_CONT_FOG                                     64\r
470 +\r
471 +#define F_CONT_AREAPORTAL                      0x8000\r
472 +\r
473 +#define F_CONT_PLAYERCLIP                      0x10000\r
474 +#define F_CONT_MONSTERCLIP                     0x20000\r
475 +#define F_CONT_TELEPORTER                      0x40000\r
476 +#define F_CONT_JUMPPAD                         0x80000\r
477 +#define F_CONT_CLUSTERPORTAL           0x100000\r
478 +#define F_CONT_DONOTENTER                      0x200000\r
479 +#define F_CONT_BOTCLIP                         0x400000\r
480 +\r
481 +#define F_CONT_ORIGIN                          0x1000000       /* removed before bsping an entity */\r
482 +\r
483 +#define F_CONT_BODY                                    0x2000000       /* should never be on a brush, only in game */\r
484 +#define F_CONT_CORPSE                          0x4000000\r
485 +#define F_CONT_DETAIL                          0x8000000       /* brushes not used for the bsp */\r
486 +#define F_CONT_STRUCTURAL                      0x10000000      /* brushes used for the bsp */\r
487 +#define F_CONT_TRANSLUCENT                     0x20000000      /* don't consume surface fragments inside */\r
488 +#define F_CONT_TRIGGER                         0x40000000\r
489 +#define F_CONT_NODROP                          0x80000000      /* don't leave bodies or items (death fog, lava) */\r
490 +\r
491 +#define F_SURF_NODAMAGE                                0x1                     /* never give falling damage */\r
492 +#define F_SURF_SLICK                           0x2                     /* effects game physics */\r
493 +#define F_SURF_SKY                                     0x4                     /* lighting from environment map */\r
494 +#define F_SURF_LADDER                          0x8\r
495 +#define F_SURF_NOIMPACT                                0x10            /* don't make missile explosions */\r
496 +#define F_SURF_NOMARKS                         0x20            /* don't leave missile marks */\r
497 +#define F_SURF_FLESH                           0x40            /* make flesh sounds and effects */\r
498 +#define F_SURF_NODRAW                          0x80            /* don't generate a drawsurface at all */\r
499 +#define F_SURF_HINT                                    0x100           /* make a primary bsp splitter */\r
500 +#define F_SURF_SKIP                                    0x200           /* completely ignore, allowing non-closed brushes */\r
501 +#define F_SURF_NOLIGHTMAP                      0x400           /* surface doesn't need a lightmap */\r
502 +#define F_SURF_POINTLIGHT                      0x800           /* generate lighting info at vertexes */\r
503 +#define F_SURF_METALSTEPS                      0x1000          /* clanking footsteps */\r
504 +#define F_SURF_NOSTEPS                         0x2000          /* no footstep sounds */\r
505 +#define F_SURF_NONSOLID                                0x4000          /* don't collide against curves with this set */\r
506 +#define F_SURF_LIGHTFILTER                     0x8000          /* act as a light filter during q3map -light */\r
507 +#define F_SURF_ALPHASHADOW                     0x10000         /* do per-pixel light shadow casting in q3map */\r
508 +#define F_SURF_NODLIGHT                                0x20000         /* don't dlight even if solid (solid lava, skies) */\r
509 +#define F_SURF_DUST                                    0x40000         /* leave a dust trail when walking on this surface */\r
510 +\r
511 +/* ydnar flags */\r
512 +#define F_SURF_VERTEXLIT                       (F_SURF_POINTLIGHT | F_SURF_NOLIGHTMAP)\r
513 +\r
514 +\r
515 +\r
516 +/* -------------------------------------------------------------------------------\r
517 +\r
518 +game_t struct\r
519 +\r
520 +------------------------------------------------------------------------------- */\r
521 +\r
522 +{\r
523 +       "qfusion",                      /* -game x */\r
524 +       "baseq3",                       /* default base game data dir */\r
525 +       ".q3a",                         /* unix home sub-dir */\r
526 +       "quake",                        /* magic path word */\r
527 +       "scripts",                      /* shader directory */\r
528 +       2048,                           /* max lightmapped surface verts */\r
529 +       2048,                           /* max surface verts */\r
530 +       12288,                          /* max surface indexes */\r
531 +       qtrue,                          /* flares */\r
532 +       "flareshader",          /* default flare shader */\r
533 +       qfalse,                         /* wolf lighting model? */\r
534 +       512,                            /* lightmap width/height */\r
535 +       1.0f,                           /* lightmap gamma */\r
536 +       1.0f,                           /* lightmap exposure */\r
537 +       1.0f,                           /* lightmap compensate */\r
538 +       1.0f,                           /* lightgrid scale */\r
539 +       1.0f,                           /* lightgrid ambient scale */\r
540 +       qfalse,                         /* disable shader lightstyles hack */\r
541 +       qfalse,                         /* keep light entities on bsp */\r
542 +       8,                                      /* default patchMeta subdivisions tolerance */\r
543 +       qfalse,                         /* patch casting enabled */\r
544 +       qfalse,                         /* compile deluxemaps */\r
545 +       0,                                      /* deluxemaps default mode */\r
546 +       "FBSP",                         /* bsp file prefix */\r
547 +       1,                                      /* bsp file version */\r
548 +       qfalse,                         /* cod-style lump len/ofs order */\r
549 +       LoadRBSPFile,           /* bsp load function */\r
550 +       WriteRBSPFile,          /* bsp write function */\r
551 +\r
552 +       {\r
553 +               /* name                         contentFlags                            contentFlagsClear                       surfaceFlags                            surfaceFlagsClear                       compileFlags                            compileFlagsClear */\r
554 +               \r
555 +               /* default */\r
556 +               { "default",            F_CONT_SOLID,                           -1,                                                     0,                                                      -1,                                                     C_SOLID,                                        -1 },\r
557 +               \r
558 +               \r
559 +               /* ydnar */\r
560 +               { "lightgrid",          0,                                                      0,                                                      0,                                                      0,                                                      C_LIGHTGRID,                            0 },\r
561 +               { "antiportal",         0,                                                      0,                                                      0,                                                      0,                                                      C_ANTIPORTAL,                           0 },\r
562 +               { "skip",                       0,                                                      0,                                                      0,                                                      0,                                                      C_SKIP,                                         0 },\r
563 +               \r
564 +               \r
565 +               /* compiler */\r
566 +               { "origin",                     F_CONT_ORIGIN,                          F_CONT_SOLID,                           0,                                                      0,                                                      C_ORIGIN | C_TRANSLUCENT,       C_SOLID },\r
567 +               { "areaportal",         F_CONT_AREAPORTAL,                      F_CONT_SOLID,                           0,                                                      0,                                                      C_AREAPORTAL | C_TRANSLUCENT,   C_SOLID },\r
568 +               { "trans",                      F_CONT_TRANSLUCENT,                     0,                                                      0,                                                      0,                                                      C_TRANSLUCENT,                          0 },\r
569 +               { "detail",                     F_CONT_DETAIL,                          0,                                                      0,                                                      0,                                                      C_DETAIL,                                       0 },\r
570 +               { "structural",         F_CONT_STRUCTURAL,                      0,                                                      0,                                                      0,                                                      C_STRUCTURAL,                           0 },\r
571 +               { "hint",                       0,                                                      0,                                                      F_SURF_HINT,                            0,                                                      C_HINT,                                         0 },\r
572 +               { "nodraw",                     0,                                                      0,                                                      F_SURF_NODRAW,                          0,                                                      C_NODRAW,                                       0 },\r
573 +               \r
574 +               { "alphashadow",        0,                                                      0,                                                      F_SURF_ALPHASHADOW,                     0,                                                      C_ALPHASHADOW | C_TRANSLUCENT,  0 },\r
575 +               { "lightfilter",        0,                                                      0,                                                      F_SURF_LIGHTFILTER,                     0,                                                      C_LIGHTFILTER | C_TRANSLUCENT,  0 },\r
576 +               { "nolightmap",         0,                                                      0,                                                      F_SURF_VERTEXLIT,                       0,                                                      C_VERTEXLIT,                            0 },\r
577 +               { "pointlight",         0,                                                      0,                                                      F_SURF_VERTEXLIT,                       0,                                                      C_VERTEXLIT,                            0 },\r
578 +               \r
579 +               \r
580 +               /* game */\r
581 +               { "nonsolid",           0,                                                      F_CONT_SOLID,                           F_SURF_NONSOLID,                        0,                                                      0,                                                      C_SOLID },\r
582 +               \r
583 +               { "trigger",            F_CONT_TRIGGER,                         F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
584 +               \r
585 +               { "water",                      F_CONT_WATER,                           F_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },\r
586 +               { "slime",                      F_CONT_SLIME,                           F_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },\r
587 +               { "lava",                       F_CONT_LAVA,                            F_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },\r
588 +               \r
589 +               { "playerclip",         F_CONT_PLAYERCLIP,                      F_CONT_SOLID,                           0,                                                      0,                                                      C_DETAIL | C_TRANSLUCENT,       C_SOLID },\r
590 +               { "monsterclip",        F_CONT_MONSTERCLIP,                     F_CONT_SOLID,                           0,                                                      0,                                                      C_DETAIL | C_TRANSLUCENT,       C_SOLID },\r
591 +               { "nodrop",                     F_CONT_NODROP,                          F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
592 +               \r
593 +               { "clusterportal",      F_CONT_CLUSTERPORTAL,           F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
594 +               { "donotenter",         F_CONT_DONOTENTER,                      F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
595 +               { "botclip",            F_CONT_BOTCLIP,                         F_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
596 +               \r
597 +               { "fog",                        F_CONT_FOG,                                     F_CONT_SOLID,                           0,                                                      0,                                                      C_FOG,                                          C_SOLID },\r
598 +               { "sky",                        0,                                                      0,                                                      F_SURF_SKY,                                     0,                                                      C_SKY,                                          0 },\r
599 +               \r
600 +               { "slick",                      0,                                                      0,                                                      F_SURF_SLICK,                           0,                                                      0,                                                      0 },\r
601 +               \r
602 +               { "noimpact",           0,                                                      0,                                                      F_SURF_NOIMPACT,                        0,                                                      0,                                                      0 },\r
603 +               { "nomarks",            0,                                                      0,                                                      F_SURF_NOMARKS,                         0,                                                      C_NOMARKS,                                      0 },\r
604 +               { "ladder",                     0,                                                      0,                                                      F_SURF_LADDER,                          0,                                                      0,                                                      0 },\r
605 +               { "nodamage",           0,                                                      0,                                                      F_SURF_NODAMAGE,                        0,                                                      0,                                                      0 },\r
606 +               { "metalsteps",         0,                                                      0,                                                      F_SURF_METALSTEPS,                      0,                                                      0,                                                      0 },\r
607 +               { "flesh",                      0,                                                      0,                                                      F_SURF_FLESH,                           0,                                                      0,                                                      0 },\r
608 +               { "nosteps",            0,                                                      0,                                                      F_SURF_NOSTEPS,                         0,                                                      0,                                                      0 },\r
609 +               { "nodlight",           0,                                                      0,                                                      F_SURF_NODLIGHT,                        0,                                                      0,                                                      0 },\r
610 +               { "dust",                       0,                                                      0,                                                      F_SURF_DUST,                            0,                                                      0,                                                      0 },\r
611 +               \r
612 +               \r
613 +               /* null */\r
614 +               { NULL, 0, 0, 0, 0, 0, 0 }\r
615 +       }\r
616 +}\r
617 +\r
618 +\r
619 +\r
620 +/* end marker */\r
621 +#endif\r
622 +\r
623 Index: game_quake3.h\r
624 ===================================================================\r
625 --- game_quake3.h       (revision 158)\r
626 +++ game_quake3.h       (working copy)\r
627 @@ -112,7 +112,16 @@\r
628         qfalse,                         /* wolf lighting model? */
629         128,                            /* lightmap width/height */
630         1.0f,                           /* lightmap gamma */
631 +       1.0f,                           /* lightmap exposure */
632         1.0f,                           /* lightmap compensate */
633 +       1.0f,                           /* lightgrid scale */
634 +       1.0f,                           /* lightgrid ambient scale */
635 +       qfalse,                         /* disable shader lightstyles hack */
636 +       qfalse,                         /* keep light entities on bsp */
637 +       8,                                      /* default patchMeta subdivisions tolerance */
638 +       qfalse,                         /* patch casting enabled */
639 +       qfalse,                         /* compile deluxemaps */
640 +       0,                                      /* deluxemaps default mode */
641         "IBSP",                         /* bsp file prefix */
642         46,                                     /* bsp file version */
643         qfalse,                         /* cod-style lump len/ofs order */
644 Index: game_sof2.h\r
645 ===================================================================\r
646 --- game_sof2.h (revision 158)\r
647 +++ game_sof2.h (working copy)\r
648 @@ -139,7 +139,16 @@\r
649         qfalse,                                 /* wolf lighting model? */
650         128,                                    /* lightmap width/height */
651         1.0f,                                   /* lightmap gamma */
652 +       1.0f,                                   /* lightmap exposure */
653         1.0f,                                   /* lightmap compensate */
654 +       1.0f,                           /* lightgrid scale */
655 +       1.0f,                           /* lightgrid ambient scale */
656 +       qfalse,                         /* disable shader lightstyles hack */
657 +       qfalse,                         /* keep light entities on bsp */
658 +       8,                                      /* default patchMeta subdivisions tolerance */
659 +       qfalse,                         /* patch casting enabled */
660 +       qfalse,                         /* compile deluxemaps */
661 +       0,                                      /* deluxemaps default mode */
662         "RBSP",                                 /* bsp file prefix */
663         1,                                              /* bsp file version */
664         qfalse,                                 /* cod-style lump len/ofs order */
665 Index: game_tenebrae.h\r
666 ===================================================================\r
667 --- game_tenebrae.h     (revision 158)\r
668 +++ game_tenebrae.h     (working copy)\r
669 @@ -112,7 +112,16 @@\r
670         qfalse,                         /* wolf lighting model? */
671         512,                            /* lightmap width/height */
672         2.0f,                           /* lightmap gamma */
673 +       1.0f,                           /* lightmap exposure */
674         1.0f,                           /* lightmap compensate */
675 +       1.0f,                           /* lightgrid scale */
676 +       1.0f,                           /* lightgrid ambient scale */
677 +       qtrue,                          /* disable shader lightstyles hack */
678 +       qfalse,                         /* keep light entities on bsp */
679 +       8,                                      /* default patchMeta subdivisions tolerance */
680 +       qfalse,                         /* patch casting enabled */
681 +       qtrue,                          /* compile deluxemaps */
682 +       0,                                      /* deluxemaps default mode */
683         "IBSP",                         /* bsp file prefix */
684         46,                                     /* bsp file version */
685         qfalse,                         /* cod-style lump len/ofs order */
686 Index: game_tremulous.h\r
687 ===================================================================\r
688 --- game_tremulous.h    (revision 158)\r
689 +++ game_tremulous.h    (working copy)\r
690 @@ -1,160 +1,169 @@\r
691 -/* -------------------------------------------------------------------------------
692 -
693 -Copyright (C) 1999-2006 Id Software, Inc. and contributors.
694 -For a list of contributors, see the accompanying CONTRIBUTORS file.
695 -
696 -This file is part of GtkRadiant.
697 -
698 -GtkRadiant is free software; you can redistribute it and/or modify
699 -it under the terms of the GNU General Public License as published by
700 -the Free Software Foundation; either version 2 of the License, or
701 -(at your option) any later version.
702 -
703 -GtkRadiant is distributed in the hope that it will be useful,
704 -but WITHOUT ANY WARRANTY; without even the implied warranty of
705 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
706 -GNU General Public License for more details.
707 -
708 -You should have received a copy of the GNU General Public License
709 -along with GtkRadiant; if not, write to the Free Software
710 -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
711 -
712 -----------------------------------------------------------------------------------
713 -
714 -This code has been altered significantly from its original form, to support
715 -several games based on the Quake III Arena engine, in the form of "Q3Map2."
716 -
717 -------------------------------------------------------------------------------- */
718 -
719 -/* Tremulous support, by LinuxManMikeC */
720 -
721 -
722 -/* marker */
723 -#ifndef GAME_TREMULOUS_H
724 -#define GAME_TREMULOUS_H
725 -
726 -
727 -
728 -/* -------------------------------------------------------------------------------
729 -
730 -content and surface flags - also uses defines from game_quake3.h
731 -
732 -------------------------------------------------------------------------------- */
733 -#define TREM_CONT_NOALIENBUILD         0x1000
734 -#define TREM_CONT_NOHUMANBUILD         0x2000
735 -#define TREM_CONT_NOBUILD              0x4000
736 -  
737 -#define TREM_SURF_NOALIENBUILDSURFACE  0x80000 
738 -#define TREM_SURF_NOHUMANBUILDSURFACE  0x100000
739 -#define TREM_SURF_NOBUILDSURFACE       0x200000
740 -
741 -
742 -
743 -/* -------------------------------------------------------------------------------
744 -
745 -game_t struct
746 -
747 -------------------------------------------------------------------------------- */
748 -
749 -{
750 -       "tremulous",                    /* -game x */
751 -       "base",                 /* default base game data dir */
752 -       ".tremulous",                           /* unix home sub-dir */
753 -       "tremulous",                    /* magic path word - think this is right for trem*/
754 -       "scripts",                      /* shader directory */
755 -       64,                                     /* max lightmapped surface verts */
756 -       999,                            /* max surface verts */
757 -       6000,                           /* max surface indexes */
758 -       qfalse,                         /* flares */
759 -       "flareshader",          /* default flare shader */
760 -       qfalse,                         /* wolf lighting model? */
761 -       128,                            /* lightmap width/height */
762 -       1.0f,                           /* lightmap gamma */
763 -       1.0f,                           /* lightmap compensate */
764 -       "IBSP",                         /* bsp file prefix */
765 -       46,                                     /* bsp file version */
766 -       qfalse,                         /* cod-style lump len/ofs order */
767 -       LoadIBSPFile,           /* bsp load function */
768 -       WriteIBSPFile,          /* bsp write function */
769 -
770 -       {
771 -               /* name                         contentFlags                            contentFlagsClear                       surfaceFlags                            surfaceFlagsClear                       compileFlags                            compileFlagsClear */
772 -               
773 -               /* default */
774 -               { "default",            Q_CONT_SOLID,                           -1,                                                     0,                                                      -1,                                                     C_SOLID,                                        -1 },
775 -               
776 -               
777 -               /* ydnar */
778 -               { "lightgrid",          0,                                                      0,                                                      0,                                                      0,                                                      C_LIGHTGRID,                            0 },
779 -               { "antiportal",         0,                                                      0,                                                      0,                                                      0,                                                      C_ANTIPORTAL,                           0 },
780 -               { "skip",                       0,                                                      0,                                                      0,                                                      0,                                                      C_SKIP,                                         0 },
781 -               
782 -               
783 -               /* compiler */
784 -               { "origin",                     Q_CONT_ORIGIN,                          Q_CONT_SOLID,                           0,                                                      0,                                                      C_ORIGIN | C_TRANSLUCENT,       C_SOLID },
785 -               { "areaportal",         Q_CONT_AREAPORTAL,                      Q_CONT_SOLID,                           0,                                                      0,                                                      C_AREAPORTAL | C_TRANSLUCENT,   C_SOLID },
786 -               { "trans",                      Q_CONT_TRANSLUCENT,                     0,                                                      0,                                                      0,                                                      C_TRANSLUCENT,                          0 },
787 -               { "detail",                     Q_CONT_DETAIL,                          0,                                                      0,                                                      0,                                                      C_DETAIL,                                       0 },
788 -               { "structural",         Q_CONT_STRUCTURAL,                      0,                                                      0,                                                      0,                                                      C_STRUCTURAL,                           0 },
789 -               { "hint",                       0,                                                      0,                                                      Q_SURF_HINT,                            0,                                                      C_HINT,                                         0 },
790 -               { "nodraw",                     0,                                                      0,                                                      Q_SURF_NODRAW,                          0,                                                      C_NODRAW,                                       0 },
791 -               
792 -               { "alphashadow",        0,                                                      0,                                                      Q_SURF_ALPHASHADOW,                     0,                                                      C_ALPHASHADOW | C_TRANSLUCENT,  0 },
793 -               { "lightfilter",        0,                                                      0,                                                      Q_SURF_LIGHTFILTER,                     0,                                                      C_LIGHTFILTER | C_TRANSLUCENT,  0 },
794 -               { "nolightmap",         0,                                                      0,                                                      Q_SURF_VERTEXLIT,                       0,                                                      C_VERTEXLIT,                            0 },
795 -               { "pointlight",         0,                                                      0,                                                      Q_SURF_VERTEXLIT,                       0,                                                      C_VERTEXLIT,                            0 },
796 -               
797 -               
798 -               /* game */
799 -               { "nonsolid",           0,                                                      Q_CONT_SOLID,                           Q_SURF_NONSOLID,                        0,                                                      0,                                                      C_SOLID },
800 -               
801 -               { "trigger",            Q_CONT_TRIGGER,                         Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
802 -               
803 -               { "water",                      Q_CONT_WATER,                           Q_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },
804 -               { "slime",                      Q_CONT_SLIME,                           Q_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },
805 -               { "lava",                       Q_CONT_LAVA,                            Q_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },
806 -               
807 -               { "playerclip",         Q_CONT_PLAYERCLIP,                      Q_CONT_SOLID,                           0,                                                      0,                                                      C_DETAIL | C_TRANSLUCENT,       C_SOLID },
808 -               { "monsterclip",        Q_CONT_MONSTERCLIP,                     Q_CONT_SOLID,                           0,                                                      0,                                                      C_DETAIL | C_TRANSLUCENT,       C_SOLID },
809 -               { "nodrop",                     Q_CONT_NODROP,                          Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
810 -               
811 -               { "clusterportal",      Q_CONT_CLUSTERPORTAL,           Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
812 -               { "donotenter",         Q_CONT_DONOTENTER,                      Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
813 -               { "botclip",            Q_CONT_BOTCLIP,                         Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },
814 -               
815 -               { "fog",                        Q_CONT_FOG,                                     Q_CONT_SOLID,                           0,                                                      0,                                                      C_FOG,                                          C_SOLID },
816 -               { "sky",                        0,                                                      0,                                                      Q_SURF_SKY,                                     0,                                                      C_SKY,                                          0 },
817 -               
818 -               { "slick",                      0,                                                      0,                                                      Q_SURF_SLICK,                           0,                                                      0,                                                      0 },
819 -               
820 -               { "noimpact",           0,                                                      0,                                                      Q_SURF_NOIMPACT,                        0,                                                      0,                                                      0 },
821 -               { "nomarks",            0,                                                      0,                                                      Q_SURF_NOMARKS,                         0,                                                      C_NOMARKS,                                      0 },
822 -               { "ladder",                     0,                                                      0,                                                      Q_SURF_LADDER,                          0,                                                      0,                                                      0 },
823 -               { "nodamage",           0,                                                      0,                                                      Q_SURF_NODAMAGE,                        0,                                                      0,                                                      0 },
824 -               { "metalsteps",         0,                                                      0,                                                      Q_SURF_METALSTEPS,                      0,                                                      0,                                                      0 },
825 -               { "flesh",                      0,                                                      0,                                                      Q_SURF_FLESH,                           0,                                                      0,                                                      0 },
826 -               { "nosteps",            0,                                                      0,                                                      Q_SURF_NOSTEPS,                         0,                                                      0,                                                      0 },
827 -               { "nodlight",           0,                                                      0,                                                      Q_SURF_NODLIGHT,                        0,                                                      0,                                                      0 },
828 -               { "dust",                       0,                                                      0,                                                      Q_SURF_DUST,                            0,                                                      0,                                                      0 },
829 -               
830 -               
831 -               /* tremulous */
832 -               {"noalienbuild",                        TREM_CONT_NOALIENBUILD,0,0,0,0,0},
833 -               {"nohumanbuild",                        TREM_CONT_NOHUMANBUILD,0,0,0,0,0},
834 -               {"nobuild",                                     TREM_CONT_NOBUILD,0,0,0,0,0},
835 -               
836 -               {"noalienbuildsurface", 0,0,TREM_SURF_NOALIENBUILDSURFACE,0,0,0},
837 -               {"nohumanbuildsurface", 0,0,TREM_SURF_NOHUMANBUILDSURFACE,0,0,0},
838 -               {"nobuildsurface",              0,0,TREM_SURF_NOBUILDSURFACE,0,0,0},
839 -               
840 -               
841 -               /* null */
842 -               { NULL, 0, 0, 0, 0, 0, 0 }
843 -       }
844 -}
845 -
846 -
847 -
848 -/* end marker */
849 -#endif
850 -
851 +/* -------------------------------------------------------------------------------\r
852 +\r
853 +Copyright (C) 1999-2006 Id Software, Inc. and contributors.\r
854 +For a list of contributors, see the accompanying CONTRIBUTORS file.\r
855 +\r
856 +This file is part of GtkRadiant.\r
857 +\r
858 +GtkRadiant is free software; you can redistribute it and/or modify\r
859 +it under the terms of the GNU General Public License as published by\r
860 +the Free Software Foundation; either version 2 of the License, or\r
861 +(at your option) any later version.\r
862 +\r
863 +GtkRadiant is distributed in the hope that it will be useful,\r
864 +but WITHOUT ANY WARRANTY; without even the implied warranty of\r
865 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
866 +GNU General Public License for more details.\r
867 +\r
868 +You should have received a copy of the GNU General Public License\r
869 +along with GtkRadiant; if not, write to the Free Software\r
870 +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
871 +\r
872 +----------------------------------------------------------------------------------\r
873 +\r
874 +This code has been altered significantly from its original form, to support\r
875 +several games based on the Quake III Arena engine, in the form of "Q3Map2."\r
876 +\r
877 +------------------------------------------------------------------------------- */\r
878 +\r
879 +/* Tremulous support, by LinuxManMikeC */\r
880 +\r
881 +\r
882 +/* marker */\r
883 +#ifndef GAME_TREMULOUS_H\r
884 +#define GAME_TREMULOUS_H\r
885 +\r
886 +\r
887 +\r
888 +/* -------------------------------------------------------------------------------\r
889 +\r
890 +content and surface flags - also uses defines from game_quake3.h\r
891 +\r
892 +------------------------------------------------------------------------------- */\r
893 +#define TREM_CONT_NOALIENBUILD         0x1000\r
894 +#define TREM_CONT_NOHUMANBUILD         0x2000\r
895 +#define TREM_CONT_NOBUILD              0x4000\r
896 +  \r
897 +#define TREM_SURF_NOALIENBUILDSURFACE  0x80000 \r
898 +#define TREM_SURF_NOHUMANBUILDSURFACE  0x100000\r
899 +#define TREM_SURF_NOBUILDSURFACE       0x200000\r
900 +\r
901 +\r
902 +\r
903 +/* -------------------------------------------------------------------------------\r
904 +\r
905 +game_t struct\r
906 +\r
907 +------------------------------------------------------------------------------- */\r
908 +\r
909 +{\r
910 +       "tremulous",                    /* -game x */\r
911 +       "base",                 /* default base game data dir */\r
912 +       ".tremulous",                           /* unix home sub-dir */\r
913 +       "tremulous",                    /* magic path word - think this is right for trem*/\r
914 +       "scripts",                      /* shader directory */\r
915 +       64,                                     /* max lightmapped surface verts */\r
916 +       999,                            /* max surface verts */\r
917 +       6000,                           /* max surface indexes */\r
918 +       qfalse,                         /* flares */\r
919 +       "flareshader",          /* default flare shader */\r
920 +       qfalse,                         /* wolf lighting model? */\r
921 +       128,                            /* lightmap width/height */\r
922 +       1.0f,                           /* lightmap gamma */\r
923 +       1.0f,                           /* lightmap exposure */\r
924 +       1.0f,                           /* lightmap compensate */\r
925 +       1.0f,                           /* lightgrid scale */\r
926 +       1.0f,                           /* lightgrid ambient scale */\r
927 +       qfalse,                         /* disable shader lightstyles hack */\r
928 +       qfalse,                         /* keep light entities on bsp */\r
929 +       8,                                      /* default patchMeta subdivisions tolerance */\r
930 +       qfalse,                         /* patch casting enabled */\r
931 +       qfalse,                         /* compile deluxemaps */\r
932 +       0,                                      /* deluxemaps default mode */\r
933 +       "IBSP",                         /* bsp file prefix */\r
934 +       46,                                     /* bsp file version */\r
935 +       qfalse,                         /* cod-style lump len/ofs order */\r
936 +       LoadIBSPFile,           /* bsp load function */\r
937 +       WriteIBSPFile,          /* bsp write function */\r
938 +\r
939 +       {\r
940 +               /* name                         contentFlags                            contentFlagsClear                       surfaceFlags                            surfaceFlagsClear                       compileFlags                            compileFlagsClear */\r
941 +               \r
942 +               /* default */\r
943 +               { "default",            Q_CONT_SOLID,                           -1,                                                     0,                                                      -1,                                                     C_SOLID,                                        -1 },\r
944 +               \r
945 +               \r
946 +               /* ydnar */\r
947 +               { "lightgrid",          0,                                                      0,                                                      0,                                                      0,                                                      C_LIGHTGRID,                            0 },\r
948 +               { "antiportal",         0,                                                      0,                                                      0,                                                      0,                                                      C_ANTIPORTAL,                           0 },\r
949 +               { "skip",                       0,                                                      0,                                                      0,                                                      0,                                                      C_SKIP,                                         0 },\r
950 +               \r
951 +               \r
952 +               /* compiler */\r
953 +               { "origin",                     Q_CONT_ORIGIN,                          Q_CONT_SOLID,                           0,                                                      0,                                                      C_ORIGIN | C_TRANSLUCENT,       C_SOLID },\r
954 +               { "areaportal",         Q_CONT_AREAPORTAL,                      Q_CONT_SOLID,                           0,                                                      0,                                                      C_AREAPORTAL | C_TRANSLUCENT,   C_SOLID },\r
955 +               { "trans",                      Q_CONT_TRANSLUCENT,                     0,                                                      0,                                                      0,                                                      C_TRANSLUCENT,                          0 },\r
956 +               { "detail",                     Q_CONT_DETAIL,                          0,                                                      0,                                                      0,                                                      C_DETAIL,                                       0 },\r
957 +               { "structural",         Q_CONT_STRUCTURAL,                      0,                                                      0,                                                      0,                                                      C_STRUCTURAL,                           0 },\r
958 +               { "hint",                       0,                                                      0,                                                      Q_SURF_HINT,                            0,                                                      C_HINT,                                         0 },\r
959 +               { "nodraw",                     0,                                                      0,                                                      Q_SURF_NODRAW,                          0,                                                      C_NODRAW,                                       0 },\r
960 +               \r
961 +               { "alphashadow",        0,                                                      0,                                                      Q_SURF_ALPHASHADOW,                     0,                                                      C_ALPHASHADOW | C_TRANSLUCENT,  0 },\r
962 +               { "lightfilter",        0,                                                      0,                                                      Q_SURF_LIGHTFILTER,                     0,                                                      C_LIGHTFILTER | C_TRANSLUCENT,  0 },\r
963 +               { "nolightmap",         0,                                                      0,                                                      Q_SURF_VERTEXLIT,                       0,                                                      C_VERTEXLIT,                            0 },\r
964 +               { "pointlight",         0,                                                      0,                                                      Q_SURF_VERTEXLIT,                       0,                                                      C_VERTEXLIT,                            0 },\r
965 +               \r
966 +               \r
967 +               /* game */\r
968 +               { "nonsolid",           0,                                                      Q_CONT_SOLID,                           Q_SURF_NONSOLID,                        0,                                                      0,                                                      C_SOLID },\r
969 +               \r
970 +               { "trigger",            Q_CONT_TRIGGER,                         Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
971 +               \r
972 +               { "water",                      Q_CONT_WATER,                           Q_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },\r
973 +               { "slime",                      Q_CONT_SLIME,                           Q_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },\r
974 +               { "lava",                       Q_CONT_LAVA,                            Q_CONT_SOLID,                           0,                                                      0,                                                      C_LIQUID | C_TRANSLUCENT,       C_SOLID },\r
975 +               \r
976 +               { "playerclip",         Q_CONT_PLAYERCLIP,                      Q_CONT_SOLID,                           0,                                                      0,                                                      C_DETAIL | C_TRANSLUCENT,       C_SOLID },\r
977 +               { "monsterclip",        Q_CONT_MONSTERCLIP,                     Q_CONT_SOLID,                           0,                                                      0,                                                      C_DETAIL | C_TRANSLUCENT,       C_SOLID },\r
978 +               { "nodrop",                     Q_CONT_NODROP,                          Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
979 +               \r
980 +               { "clusterportal",      Q_CONT_CLUSTERPORTAL,           Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
981 +               { "donotenter",         Q_CONT_DONOTENTER,                      Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
982 +               { "botclip",            Q_CONT_BOTCLIP,                         Q_CONT_SOLID,                           0,                                                      0,                                                      C_TRANSLUCENT,                          C_SOLID },\r
983 +               \r
984 +               { "fog",                        Q_CONT_FOG,                                     Q_CONT_SOLID,                           0,                                                      0,                                                      C_FOG,                                          C_SOLID },\r
985 +               { "sky",                        0,                                                      0,                                                      Q_SURF_SKY,                                     0,                                                      C_SKY,                                          0 },\r
986 +               \r
987 +               { "slick",                      0,                                                      0,                                                      Q_SURF_SLICK,                           0,                                                      0,                                                      0 },\r
988 +               \r
989 +               { "noimpact",           0,                                                      0,                                                      Q_SURF_NOIMPACT,                        0,                                                      0,                                                      0 },\r
990 +               { "nomarks",            0,                                                      0,                                                      Q_SURF_NOMARKS,                         0,                                                      C_NOMARKS,                                      0 },\r
991 +               { "ladder",                     0,                                                      0,                                                      Q_SURF_LADDER,                          0,                                                      0,                                                      0 },\r
992 +               { "nodamage",           0,                                                      0,                                                      Q_SURF_NODAMAGE,                        0,                                                      0,                                                      0 },\r
993 +               { "metalsteps",         0,                                                      0,                                                      Q_SURF_METALSTEPS,                      0,                                                      0,                                                      0 },\r
994 +               { "flesh",                      0,                                                      0,                                                      Q_SURF_FLESH,                           0,                                                      0,                                                      0 },\r
995 +               { "nosteps",            0,                                                      0,                                                      Q_SURF_NOSTEPS,                         0,                                                      0,                                                      0 },\r
996 +               { "nodlight",           0,                                                      0,                                                      Q_SURF_NODLIGHT,                        0,                                                      0,                                                      0 },\r
997 +               { "dust",                       0,                                                      0,                                                      Q_SURF_DUST,                            0,                                                      0,                                                      0 },\r
998 +               \r
999 +               \r
1000 +               /* tremulous */\r
1001 +               {"noalienbuild",                        TREM_CONT_NOALIENBUILD,0,0,0,0,0},\r
1002 +               {"nohumanbuild",                        TREM_CONT_NOHUMANBUILD,0,0,0,0,0},\r
1003 +               {"nobuild",                                     TREM_CONT_NOBUILD,0,0,0,0,0},\r
1004 +               \r
1005 +               {"noalienbuildsurface", 0,0,TREM_SURF_NOALIENBUILDSURFACE,0,0,0},\r
1006 +               {"nohumanbuildsurface", 0,0,TREM_SURF_NOHUMANBUILDSURFACE,0,0,0},\r
1007 +               {"nobuildsurface",              0,0,TREM_SURF_NOBUILDSURFACE,0,0,0},\r
1008 +               \r
1009 +               \r
1010 +               /* null */\r
1011 +               { NULL, 0, 0, 0, 0, 0, 0 }\r
1012 +       }\r
1013 +}\r
1014 +\r
1015 +\r
1016 +\r
1017 +/* end marker */\r
1018 +#endif\r
1019 +\r
1020 Index: game_wolf.h\r
1021 ===================================================================\r
1022 --- game_wolf.h (revision 158)\r
1023 +++ game_wolf.h (working copy)\r
1024 @@ -129,7 +129,16 @@\r
1025         qtrue,                          /* wolf lighting model? */
1026         128,                            /* lightmap width/height */
1027         1.0f,                           /* lightmap gamma */
1028 +       1.0f,                           /* lightmap exposure */
1029         1.0f,                           /* lightmap compensate */
1030 +       1.0f,                           /* lightgrid scale */
1031 +       1.0f,                           /* lightgrid ambient scale */
1032 +       qfalse,                         /* disable shader lightstyles hack */
1033 +       qfalse,                         /* keep light entities on bsp */
1034 +       8,                                      /* default patchMeta subdivisions tolerance */
1035 +       qfalse,                         /* patch casting enabled */
1036 +       qfalse,                         /* compile deluxemaps */
1037 +       0,                                      /* deluxemaps default mode */
1038         "IBSP",                         /* bsp file prefix */
1039         47,                                     /* bsp file version */
1040         qfalse,                         /* cod-style lump len/ofs order */
1041 Index: game_wolfet.h\r
1042 ===================================================================\r
1043 --- game_wolfet.h       (revision 158)\r
1044 +++ game_wolfet.h       (working copy)\r
1045 @@ -66,7 +66,16 @@\r
1046         qtrue,                          /* wolf lighting model? */
1047         128,                            /* lightmap width/height */
1048         1.0f,                           /* lightmap gamma */
1049 +       1.0f,                           /* lightmap exposure */
1050         1.0f,                           /* lightmap compensate */
1051 +       1.0f,                           /* lightgrid scale */
1052 +       1.0f,                           /* lightgrid ambient scale */
1053 +       qfalse,                         /* disable shader lightstyles hack */
1054 +       qfalse,                         /* keep light entities on bsp */
1055 +       8,                                      /* default patchMeta subdivisions tolerance */
1056 +       qfalse,                         /* patch casting enabled */
1057 +       qfalse,                         /* compile deluxemaps */
1058 +       0,                                      /* deluxemaps default mode */
1059         "IBSP",                         /* bsp file prefix */
1060         47,                                     /* bsp file version */
1061         qfalse,                         /* cod-style lump len/ofs order */
1062 Index: light.c\r
1063 ===================================================================\r
1064 --- light.c     (revision 158)\r
1065 +++ light.c     (working copy)\r
1066 @@ -313,7 +313,15 @@\r
1067                         flags |= LIGHT_GRID;
1068                         flags &= ~LIGHT_SURFACES;
1069                 }
1070 -               
1071 +
1072 +               /* vortex: unnormalized? */
1073 +               if (spawnflags & 32)
1074 +                       flags |= LIGHT_UNNORMALIZED;
1075 +
1076 +               /* vortex: distance atten? */
1077 +               if (spawnflags & 64)
1078 +                       flags |= LIGHT_ATTEN_DISTANCE;
1079 +
1080                 /* store the flags */
1081                 light->flags = flags;
1082                 
1083 @@ -357,12 +365,13 @@\r
1084                 intensity *= scale;
1085                 
1086                 /* ydnar: get deviance and samples */
1087 +               /* VorteX: now set start value for _samples when _deviance is found */
1088                 deviance = FloatForKey( e, "_deviance" );
1089                 if( deviance == 0.0f )
1090                         deviance = FloatForKey( e, "_deviation" );
1091                 if( deviance == 0.0f )
1092                         deviance = FloatForKey( e, "_jitter" );
1093 -               numSamples = IntForKey( e, "_samples" );
1094 +               numSamples = max(IntForKey( e, "_samples" ), deviance);
1095                 if( deviance < 0.0f || numSamples < 1 )
1096                 {
1097                         deviance = 0.0f;
1098 @@ -385,14 +394,16 @@\r
1099                 if( _color && _color[ 0 ] )
1100                 {
1101                         sscanf( _color, "%f %f %f", &light->color[ 0 ], &light->color[ 1 ], &light->color[ 2 ] );
1102 -                       ColorNormalize( light->color, light->color );
1103 +                       if (!(light->flags & LIGHT_UNNORMALIZED))
1104 +                       {
1105 +                               ColorNormalize( light->color, light->color );
1106 +                       }
1107                 }
1108                 else
1109                         light->color[ 0 ] = light->color[ 1 ] = light->color[ 2 ] = 1.0f;
1110 -               
1111 +
1112                 intensity = intensity * pointScale;
1113                 light->photons = intensity;
1114 -               
1115                 light->type = EMIT_POINT;
1116                 
1117                 /* set falloff threshold */
1118 @@ -741,6 +752,7 @@\r
1119         
1120         /* clear color */
1121         VectorClear( trace->color );
1122 +       VectorClear( trace->colorNoShadow );
1123         
1124         /* ydnar: early out */
1125         if( !(light->flags & LIGHT_SURFACES) || light->envelope <= 0.0f )
1126 @@ -766,7 +778,6 @@\r
1127                 float           d;
1128                 vec3_t          pushedOrigin;
1129                 
1130 -               
1131                 /* project sample point into light plane */
1132                 d = DotProduct( trace->origin, light->normal ) - light->dist;
1133                 if( d < 3.0f )
1134 @@ -881,8 +892,7 @@\r
1135                 {
1136                         float   distByNormal, radiusAtDist, sampleRadius;
1137                         vec3_t  pointAtDist, distToSample;
1138 -                       
1139 -                       
1140 +       
1141                         /* do cone calculation */
1142                         distByNormal = -DotProduct( trace->displacement, light->normal );
1143                         if( distByNormal < 0.0f )
1144 @@ -922,6 +932,9 @@\r
1145                 add = light->photons * angle;
1146                 if( add <= 0.0f )
1147                         return 0;
1148 +
1149 +               /* VorteX: set noShadow color */
1150 +               VectorScale(light->color, add, trace->colorNoShadow);
1151                 
1152                 /* setup trace */
1153                 trace->testAll = qtrue;
1154 @@ -942,6 +955,9 @@\r
1155                 /* return to sender */
1156                 return 1;
1157         }
1158 +
1159 +       /* VorteX: set noShadow color */
1160 +       VectorScale(light->color, add, trace->colorNoShadow);
1161         
1162         /* ydnar: changed to a variable number */
1163         if( add <= 0.0f || (add <= light->falloffTolerance && (light->flags & LIGHT_FAST_ACTUAL)) )
1164 @@ -1378,6 +1394,56 @@\r
1165                         break;
1166         }
1167         
1168 +       /////// Floodlighting for point //////////////////
1169 +       //do our floodlight ambient occlusion loop, and add a single contribution based on the brightest dir
1170 +       if (floodlighty)
1171 +       {
1172 +               int q;
1173 +               float addSize,f;
1174 +               vec3_t col,dir;
1175 +               col[0]=col[1]=col[2]=floodlightIntensity;
1176 +               dir[0]=dir[1]=0;
1177 +               dir[2]=1;
1178 +      
1179 +               trace.testOcclusion = qtrue;
1180 +               trace.forceSunlight = qfalse;
1181 +               trace.inhibitRadius = DEFAULT_INHIBIT_RADIUS;
1182 +               trace.testAll = qtrue;     
1183 +      
1184 +               for (q=0;q<2;q++)
1185 +               {
1186 +                       if (q==0) //upper hemisphere
1187 +                       {
1188 +                               trace.normal[0]=0;
1189 +                               trace.normal[1]=0;
1190 +                               trace.normal[2]=1;
1191 +                       }
1192 +                       else //lower hemisphere
1193 +                       {
1194 +                               trace.normal[0]=0;
1195 +                               trace.normal[1]=0;
1196 +                               trace.normal[2]=-1;
1197 +                       }
1198 +
1199 +                       f = FloodLightForSample(&trace, floodlightDistance, floodlight_lowquality);
1200 +
1201 +                       contributions[ numCon ].color[0]=col[0]*f;
1202 +                       contributions[ numCon ].color[1]=col[1]*f;
1203 +                       contributions[ numCon ].color[2]=col[2]*f;
1204 +
1205 +                       contributions[ numCon ].dir[0]=dir[0];
1206 +                       contributions[ numCon ].dir[1]=dir[1];
1207 +                       contributions[ numCon ].dir[2]=dir[2];
1208 +
1209 +                       contributions[ numCon ].style = 0;
1210 +                       numCon++;               
1211 +                       /* push average direction around */
1212 +                       addSize = VectorLength( col );
1213 +                       VectorMA( gp->dir, addSize, dir, gp->dir );
1214 +               }
1215 +       }
1216 +       /////////////////////
1217 +
1218         /* normalize to get primary light direction */
1219         VectorNormalize( gp->dir, gp->dir );
1220         
1221 @@ -1420,6 +1486,9 @@\r
1222                 
1223                 /* ambient light will be at 1/4 the value of directed light */
1224                 /* (ydnar: nuke this in favor of more dramatic lighting?) */
1225 +               /* (PM: how about actually making it work? d=1 when it got here for single lights/sun :P */
1226 +//             d = 0.25f;
1227 +               /* (Hobbes: always setting it to .25 is hardly any better) */
1228                 d = 0.25f * (1.0f - d);
1229                 VectorMA( gp->ambient[ j ], d, contributions[ i ].color, gp->ambient[ j ] );
1230         }
1231 @@ -1437,8 +1506,10 @@\r
1232                 for( j = 0; j < 3; j++ )
1233                         if( color[ j ] < minGridLight[ j ] )
1234                                 color[ j ] = minGridLight[ j ];
1235 -               ColorToBytes( color, bgp->ambient[ i ], 1.0f );
1236 -               ColorToBytes( gp->directed[ i ], bgp->directed[ i ], 1.0f );
1237 +
1238 +               /* vortex: apply gridscale and gridambientscale here */
1239 +               ColorToBytes( color, bgp->ambient[ i ], gridScale*gridAmbientScale );
1240 +               ColorToBytes( gp->directed[ i ], bgp->directed[ i ], gridScale );
1241         }
1242         
1243         /* debug code */
1244 @@ -1654,14 +1725,12 @@\r
1245         if( dirty )
1246         {
1247                 Sys_Printf( "--- DirtyRawLightmap ---\n" );
1248 -
1249 -
1250 -
1251 -
1252                 RunThreadsOnIndividual( numRawLightmaps, qtrue, DirtyRawLightmap );
1253         }
1254 -       
1255  
1256 +       /* floodlight pass */
1257 +       FloodlightRawLightmaps();
1258 +
1259         /* ydnar: set up light envelopes */
1260         SetupEnvelopes( qfalse, fast );
1261         
1262 @@ -1774,12 +1843,64 @@\r
1263         
1264         /* note it */
1265         Sys_Printf( "--- Light ---\n" );
1266 -       
1267 +       Sys_Printf( "--- ProcessGameSpecific ---\n" );
1268 +
1269         /* set standard game flags */
1270         wolfLight = game->wolfLight;
1271 +       if (wolfLight == qtrue)
1272 +               Sys_Printf( " lightning model: wolf\n" );
1273 +       else
1274 +               Sys_Printf( " lightning model: quake3\n" );
1275 +
1276         lmCustomSize = game->lightmapSize;
1277 +       Sys_Printf( " lightmap size: %d x %d pixels\n", lmCustomSize, lmCustomSize );
1278 +
1279         lightmapGamma = game->lightmapGamma;
1280 +       Sys_Printf( " lightning gamma: %f\n", lightmapGamma );
1281 +
1282         lightmapCompensate = game->lightmapCompensate;
1283 +       Sys_Printf( " lightning compensation: %f\n", lightmapCompensate );
1284 +
1285 +       lightmapExposure = game->lightmapExposure;
1286 +       Sys_Printf( " lightning exposure: %f\n", lightmapExposure );
1287 +
1288 +       gridScale = game->gridScale;
1289 +       Sys_Printf( " lightgrid scale: %f\n", gridScale );
1290 +
1291 +       gridAmbientScale = game->gridAmbientScale;
1292 +       Sys_Printf( " lightgrid ambient scale: %f\n", gridAmbientScale );
1293 +
1294 +       noStyles = game->noStyles;
1295 +       if (noStyles == qtrue)
1296 +               Sys_Printf( " shader lightstyles hack: disabled\n" );
1297 +       else
1298 +               Sys_Printf( " shader lightstyles hack: enabled\n" );
1299 +
1300 +       keepLights = game->keepLights;
1301 +       if (keepLights == qtrue)
1302 +               Sys_Printf( " keep lights: enabled\n" );
1303 +       else
1304 +               Sys_Printf( " keep lights: disabled\n" );
1305 +
1306 +       patchShadows = game->patchShadows;
1307 +       if (patchShadows == qtrue)
1308 +               Sys_Printf( " patch shadows: enabled\n" );
1309 +       else
1310 +               Sys_Printf( " patch shadows: disabled\n" );
1311 +
1312 +       deluxemap = game->deluxeMap;
1313 +       deluxemode = game->deluxeMode;
1314 +       if (deluxemap == qtrue)
1315 +       {
1316 +               if (deluxemode)
1317 +                       Sys_Printf( " deluxemapping: enabled with tangentspace deluxemaps\n" );
1318 +               else
1319 +                       Sys_Printf( " deluxemapping: enabled with modelspace deluxemaps\n" );
1320 +       }
1321 +       else
1322 +               Sys_Printf( " deluxemapping: disabled\n" );
1323 +
1324 +       Sys_Printf( "--- ProcessCommandLine ---\n" );
1325         
1326         /* process commandline arguments */
1327         for( i = 1; i < (argc - 1); i++ )
1328 @@ -1827,6 +1948,22 @@\r
1329                         Sys_Printf( "All light scaled by %f\n", f );
1330                         i++;
1331                 }
1332 +
1333 +               else if( !strcmp( argv[ i ], "-gridscale" ) )
1334 +               {
1335 +                       f = atof( argv[ i + 1 ] );
1336 +                       Sys_Printf( "Grid lightning scaled by %f\n", f );
1337 +                       gridScale *= f;
1338 +                       i++;
1339 +               }
1340 +
1341 +               else if( !strcmp( argv[ i ], "-gridambientscale" ) )
1342 +               {
1343 +                       f = atof( argv[ i + 1 ] );
1344 +                       Sys_Printf( "Grid ambient lightning scaled by %f\n", f );
1345 +                       gridAmbientScale *= f;
1346 +                       i++;
1347 +               }
1348                 
1349                 else if( !strcmp( argv[ i ], "-gamma" ) )
1350                 {
1351 @@ -1836,6 +1973,14 @@\r
1352                         i++;
1353                 }
1354                 
1355 +               else if( !strcmp( argv[ i ], "-exposure" ) )
1356 +               {
1357 +                       f = atof( argv[ i + 1 ] );
1358 +                       lightmapExposure = f;
1359 +                       Sys_Printf( "Lighting exposure set to %f\n", lightmapExposure );
1360 +                       i++;
1361 +               }
1362 +               
1363                 else if( !strcmp( argv[ i ], "-compensate" ) )
1364                 {
1365                         f = atof( argv[ i + 1 ] );
1366 @@ -1889,12 +2034,6 @@\r
1367                         Sys_Printf( "Dark lightmap seams enabled\n" );
1368                 }
1369                 
1370 -
1371 -
1372 -
1373 -
1374 -
1375 -
1376                 else if( !strcmp( argv[ i ], "-shadeangle" ) )
1377                 {
1378                         shadeAngleDegrees = atof( argv[ i + 1 ] );
1379 @@ -1927,13 +2066,28 @@\r
1380                                 Sys_Printf( "Approximating lightmaps within a byte tolerance of %d\n", approximateTolerance );
1381                         i++;
1382                 }
1383 -               
1384                 else if( !strcmp( argv[ i ], "-deluxe" ) || !strcmp( argv[ i ], "-deluxemap" ) )
1385                 {
1386                         deluxemap = qtrue;
1387                         Sys_Printf( "Generating deluxemaps for average light direction\n" );
1388                 }
1389 -               
1390 +               else if( !strcmp( argv[ i ], "-deluxemode" ))
1391 +               {
1392 +                       deluxemode = atoi( argv[ i + 1 ] );
1393 +                       if (deluxemode == 0 || deluxemode > 1 || deluxemode < 0)
1394 +                       {
1395 +                               Sys_Printf( "Generating modelspace deluxemaps\n" );
1396 +                               deluxemode = 0;
1397 +                       }
1398 +                       else 
1399 +                               Sys_Printf( "Generating tangentspace deluxemaps\n" );
1400 +                       i++;
1401 +               }
1402 +               else if( !strcmp( argv[ i ], "-nodeluxe" ) || !strcmp( argv[ i ], "-nodeluxemap" ) )
1403 +               {
1404 +                       deluxemap = qfalse;
1405 +                       Sys_Printf( "Disabling generating of deluxemaps for average light direction\n" );
1406 +               }
1407                 else if( !strcmp( argv[ i ], "-external" ) )
1408                 {
1409                         externalLightmaps = qtrue;
1410 @@ -2151,6 +2305,12 @@\r
1411                         i++;
1412                         Sys_Printf( "Default lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
1413                 }
1414 +               else if( !strcmp( argv[ i ],  "-samplescale" ) )
1415 +               {
1416 +                       sampleScale = atoi( argv[ i + 1 ] );
1417 +                       i++;
1418 +                       Sys_Printf( "Lightmaps sample scale set to %d\n", sampleScale);
1419 +               }
1420                 else if( !strcmp( argv[ i ], "-novertex" ) )
1421                 {
1422                         noVertexLighting = qtrue;
1423 @@ -2186,11 +2346,36 @@\r
1424                         noStyles = qtrue;
1425                         Sys_Printf( "Disabling lightstyles\n" );
1426                 }
1427 +               else if( !strcmp( argv[ i ], "-style" ) || !strcmp( argv[ i ], "-styles" ) )
1428 +               {
1429 +                       noStyles = qfalse;
1430 +                       Sys_Printf( "Enabling lightstyles\n" );
1431 +               }
1432 +               else if( !strcmp( argv[ i ], "-keeplights" ))
1433 +               {
1434 +                       keepLights = qtrue;
1435 +                       Sys_Printf( "Leaving light entities on map after compile\n" );
1436 +               }
1437                 else if( !strcmp( argv[ i ], "-cpma" ) )
1438                 {
1439                         cpmaHack = qtrue;
1440                         Sys_Printf( "Enabling Challenge Pro Mode Asstacular Vertex Lighting Mode (tm)\n" );
1441                 }
1442 +               else if( !strcmp( argv[ i ], "-floodlight" ) )
1443 +               {
1444 +                       floodlighty = qtrue;
1445 +                       Sys_Printf( "FloodLighting enabled\n" );
1446 +               }
1447 +               else if( !strcmp( argv[ i ], "-debugnormals" ) )
1448 +               {
1449 +                       debugnormals = qtrue;
1450 +                       Sys_Printf( "DebugNormals enabled\n" );
1451 +               }
1452 +               else if( !strcmp( argv[ i ], "-lowquality" ) )
1453 +               {
1454 +                       floodlight_lowquality = qtrue;
1455 +                       Sys_Printf( "Low Quality FloodLighting enabled\n" );
1456 +               }
1457                 
1458                 /* r7: dirtmapping */
1459                 else if( !strcmp( argv[ i ], "-dirty" ) )
1460 @@ -2212,6 +2397,7 @@\r
1461                                 Sys_Printf( "Enabling randomized dirtmapping\n" );
1462                         else
1463                                 Sys_Printf( "Enabling ordered dir mapping\n" );
1464 +                       i++;
1465                 }
1466                 else if( !strcmp( argv[ i ], "-dirtdepth" ) )
1467                 {
1468 @@ -2219,6 +2405,7 @@\r
1469                         if( dirtDepth <= 0.0f )
1470                                 dirtDepth = 128.0f;
1471                         Sys_Printf( "Dirtmapping depth set to %.1f\n", dirtDepth );
1472 +                       i++;
1473                 }
1474                 else if( !strcmp( argv[ i ], "-dirtscale" ) )
1475                 {
1476 @@ -2226,6 +2413,7 @@\r
1477                         if( dirtScale <= 0.0f )
1478                                 dirtScale = 1.0f;
1479                         Sys_Printf( "Dirtmapping scale set to %.1f\n", dirtScale );
1480 +                       i++;
1481                 }
1482                 else if( !strcmp( argv[ i ], "-dirtgain" ) )
1483                 {
1484 @@ -2233,6 +2421,7 @@\r
1485                         if( dirtGain <= 0.0f )
1486                                 dirtGain = 1.0f;
1487                         Sys_Printf( "Dirtmapping gain set to %.1f\n", dirtGain );
1488 +                       i++;
1489                 }
1490                 
1491                 /* unhandled args */
1492 @@ -2279,6 +2468,7 @@\r
1493         /* ydnar: set up optimization */
1494         SetupBrushes();
1495         SetupDirt();
1496 +       SetupFloodLight();
1497         SetupSurfaceLightmaps();
1498         
1499         /* initialize the surface facet tracing */
1500 Index: light_bounce.c\r
1501 ===================================================================\r
1502 --- light_bounce.c      (revision 158)\r
1503 +++ light_bounce.c      (working copy)\r
1504 @@ -510,7 +510,7 @@\r
1505                         break;
1506                 
1507                 case MST_TRIANGLE_SOUP:
1508 -                       numTriangleDiffuseLights;
1509 +                       numTriangleDiffuseLights++;
1510                         break;
1511                 
1512                 case MST_PATCH:
1513 Index: light_trace.c\r
1514 ===================================================================\r
1515 --- light_trace.c       (revision 158)\r
1516 +++ light_trace.c       (working copy)\r
1517 @@ -56,7 +56,7 @@\r
1518  #define GROW_TRACE_NODES               16384           //%     16384
1519  #define GROW_NODE_ITEMS                        16                      //%     256
1520  
1521 -#define MAX_TW_VERTS                   12
1522 +#define MAX_TW_VERTS                   24 // vortex: increased from 12 to 24 for ability co compile some insane maps with large curve count
1523  
1524  #define        TRACE_ON_EPSILON                0.1f
1525  
1526 Index: light_ydnar.c\r
1527 ===================================================================\r
1528 --- light_ydnar.c       (revision 158)\r
1529 +++ light_ydnar.c       (working copy)\r
1530 @@ -49,6 +49,7 @@\r
1531         int             i;
1532         float   max, gamma;
1533         vec3_t  sample;
1534 +       float   inv, dif;
1535         
1536         
1537         /* ydnar: scaling necessary for simulating r_overbrightBits on external lightmaps */
1538 @@ -72,16 +73,51 @@\r
1539                 /* gamma */
1540                 sample[ i ] = pow( sample[ i ] / 255.0f, gamma ) * 255.0f;
1541         }
1542 +
1543 +       if (lightmapExposure == 1)
1544 +       {
1545 +               /* clamp with color normalization */
1546 +               max = sample[ 0 ];
1547 +               if( sample[ 1 ] > max )
1548 +                       max = sample[ 1 ];
1549 +               if( sample[ 2 ] > max )
1550 +                       max = sample[ 2 ];
1551 +               if( max > 255.0f )
1552 +                       VectorScale( sample, (255.0f / max), sample );
1553 +       }
1554 +       else
1555 +       {
1556 +               if (lightmapExposure==0)
1557 +               {
1558 +                       lightmapExposure=1.0f;
1559 +               }
1560 +               inv=1.f/lightmapExposure;
1561 +               //Exposure
1562 +       
1563 +               max = sample[ 0 ];
1564 +               if( sample[ 1 ] > max )
1565 +                       max = sample[ 1 ];
1566 +               if( sample[ 2 ] > max )
1567 +                       max = sample[ 2 ];  
1568 +      
1569 +               dif = (1-  exp(-max * inv) )  *  255;
1570 +
1571 +               if (max >0) 
1572 +               {
1573 +                       dif = dif / max;
1574 +               }
1575 +               else
1576 +               {
1577 +                       dif = 0;
1578 +               }
1579 +
1580 +               for (i=0;i<3;i++)
1581 +               {
1582 +                       sample[i]*=dif;
1583 +               }
1584 +       }
1585 +
1586         
1587 -       /* clamp with color normalization */
1588 -       max = sample[ 0 ];
1589 -       if( sample[ 1 ] > max )
1590 -               max = sample[ 1 ];
1591 -       if( sample[ 2 ] > max )
1592 -               max = sample[ 2 ];
1593 -       if( max > 255.0f )
1594 -               VectorScale( sample, (255.0f / max), sample );
1595 -       
1596         /* compensate for ingame overbrighting/bitshifting */
1597         VectorScale( sample, (1.0f / lightmapCompensate), sample );
1598         
1599 @@ -384,7 +420,7 @@\r
1600  #define NUDGE                  0.5f
1601  #define BOGUS_NUDGE            -99999.0f
1602  
1603 -static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv, vec4_t plane, float pass, vec3_t stv[ 3 ], vec3_t ttv[ 3 ] )
1604 +static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv, vec4_t plane, float pass, vec3_t stv[ 3 ], vec3_t ttv[ 3 ], vec3_t worldverts[ 3 ] )
1605  {
1606         int                             i, x, y, numClusters, *clusters, pointCluster, *cluster;
1607         float                   *luxel, *origin, *normal, d, lightmapSampleOffset;
1608 @@ -392,6 +428,12 @@\r
1609         vec3_t                  pNormal;
1610         vec3_t                  vecs[ 3 ];
1611         vec3_t                  nudged;
1612 +       vec3_t                  cverts[ 3 ];
1613 +       vec3_t                  temp;
1614 +       vec4_t                  sideplane, hostplane;
1615 +       vec3_t                  origintwo;
1616 +       int                             j, next;
1617 +       float                   e;
1618         float                   *nudge;
1619         static float    nudges[][ 2 ] =
1620                                         {
1621 @@ -485,6 +527,51 @@\r
1622         /* non axial lightmap projection (explicit xyz) */
1623         else
1624                 VectorCopy( dv->xyz, origin );
1625 +
1626 +       //////////////////////
1627 +       //27's test to make sure samples stay within the triangle boundaries
1628 +       //1) Test the sample origin to see if it lays on the wrong side of any edge (x/y)
1629 +       //2) if it does, nudge it onto the correct side.
1630 +
1631 +       if (worldverts!=NULL)
1632 +       {
1633 +               for (j=0;j<3;j++)
1634 +               {
1635 +                       VectorCopy(worldverts[j],cverts[j]);    
1636 +               }
1637 +               PlaneFromPoints(hostplane,cverts[0],cverts[1],cverts[2]);
1638 +
1639 +               for (j=0;j<3;j++)
1640 +               {
1641 +                       for (i=0;i<3;i++)
1642 +                       {
1643 +                               //build plane using 2 edges and a normal
1644 +                               next=(i+1)%3;
1645 +
1646 +                               VectorCopy(cverts[next],temp);
1647 +                               VectorAdd(temp,hostplane,temp);
1648 +                               PlaneFromPoints(sideplane,cverts[i],cverts[ next ], temp);
1649 +
1650 +                               //planetest sample point  
1651 +                               e=DotProduct(origin,sideplane);
1652 +                               e=e-sideplane[3];
1653 +                               if (e>0)
1654 +                               {
1655 +                                       //we're bad.
1656 +                                       //VectorClear(origin);
1657 +                                       //Move the sample point back inside triangle bounds
1658 +                                       origin[0]-=sideplane[0]*(e+1);
1659 +                                       origin[1]-=sideplane[1]*(e+1);
1660 +                                       origin[2]-=sideplane[2]*(e+1);
1661 +#ifdef DEBUG_27_1
1662 +                                       VectorClear(origin);
1663 +#endif 
1664 +                               }
1665 +                       }
1666 +               }
1667 +       }
1668 +
1669 +       ////////////////////////
1670         
1671         /* planar surfaces have precalculated lightmap vectors for nudging */
1672         if( lm->plane != NULL )
1673 @@ -516,8 +603,13 @@\r
1674         else
1675                 origin[ lm->axisNum ] += lightmapSampleOffset;
1676         
1677 +       VectorCopy(origin,origintwo);
1678 +       origintwo[0]+=vecs[2][0];
1679 +       origintwo[1]+=vecs[2][1];
1680 +       origintwo[2]+=vecs[2][2];
1681 +       
1682         /* get cluster */
1683 -       pointCluster = ClusterForPointExtFilter( origin, LUXEL_EPSILON, numClusters, clusters );
1684 +       pointCluster = ClusterForPointExtFilter( origintwo, LUXEL_EPSILON, numClusters, clusters );
1685         
1686         /* another retarded hack, storing nudge count in luxel[ 1 ] */
1687         luxel[ 1 ] = 0.0f;      
1688 @@ -533,14 +625,14 @@\r
1689                         for( i = 0; i < 3; i++ )
1690                         {
1691                                 /* set nudged point*/
1692 -                               nudged[ i ] = origin[ i ] + (nudge[ 0 ] * vecs[ 0 ][ i ]) + (nudge[ 1 ] * vecs[ 1 ][ i ]);
1693 +                               nudged[ i ] = origintwo[ i ] + (nudge[ 0 ] * vecs[ 0 ][ i ]) + (nudge[ 1 ] * vecs[ 1 ][ i ]);
1694                         }
1695                         nudge += 2;
1696                         
1697                         /* get pvs cluster */
1698                         pointCluster = ClusterForPointExtFilter( nudged, LUXEL_EPSILON, numClusters, clusters ); //% + 0.625 );
1699 -                       if( pointCluster >= 0 ) 
1700 -                               VectorCopy( nudged, origin );
1701 +                       //if( pointCluster >= 0 )       
1702 +                       //      VectorCopy( nudged, origin );
1703                         luxel[ 1 ] += 1.0f;
1704                 }
1705         }
1706 @@ -550,8 +642,8 @@\r
1707         {
1708                 VectorMA( dv->xyz, lightmapSampleOffset, dv->normal, nudged );
1709                 pointCluster = ClusterForPointExtFilter( nudged, LUXEL_EPSILON, numClusters, clusters );
1710 -               if( pointCluster >= 0 )
1711 -                       VectorCopy( nudged, origin );
1712 +               //if( pointCluster >= 0 )
1713 +               //      VectorCopy( nudged, origin );
1714                 luxel[ 1 ] += 1.0f;
1715         }
1716         
1717 @@ -597,7 +689,7 @@\r
1718  than the distance between two luxels (thanks jc :)
1719  */
1720  
1721 -static void MapTriangle_r( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv[ 3 ], vec4_t plane, vec3_t stv[ 3 ], vec3_t ttv[ 3 ] )
1722 +static void MapTriangle_r( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv[ 3 ], vec4_t plane, vec3_t stv[ 3 ], vec3_t ttv[ 3 ], vec3_t worldverts[ 3 ] )
1723  {
1724         bspDrawVert_t   mid, *dv2[ 3 ];
1725         int                             max;
1726 @@ -645,7 +737,7 @@\r
1727         
1728         /* split the longest edge and map it */
1729         LerpDrawVert( dv[ max ], dv[ (max + 1) % 3 ], &mid );
1730 -       MapSingleLuxel( lm, info, &mid, plane, 1, stv, ttv );
1731 +       MapSingleLuxel( lm, info, &mid, plane, 1, stv, ttv, worldverts );
1732         
1733         /* push the point up a little bit to account for fp creep (fixme: revisit this) */
1734         //%     VectorMA( mid.xyz, 2.0f, mid.normal, mid.xyz );
1735 @@ -653,12 +745,12 @@\r
1736         /* recurse to first triangle */
1737         VectorCopy( dv, dv2 );
1738         dv2[ max ] = &mid;
1739 -       MapTriangle_r( lm, info, dv2, plane, stv, ttv );
1740 +       MapTriangle_r( lm, info, dv2, plane, stv, ttv, worldverts );
1741         
1742         /* recurse to second triangle */
1743         VectorCopy( dv, dv2 );
1744         dv2[ (max + 1) % 3 ] = &mid;
1745 -       MapTriangle_r( lm, info, dv2, plane, stv, ttv );
1746 +       MapTriangle_r( lm, info, dv2, plane, stv, ttv, worldverts );
1747  }
1748  
1749  
1750 @@ -674,8 +766,8 @@\r
1751         int                             i;
1752         vec4_t                  plane;
1753         vec3_t                  *stv, *ttv, stvStatic[ 3 ], ttvStatic[ 3 ];
1754 +       vec3_t                  worldverts[ 3 ];
1755         
1756 -       
1757         /* get plane if possible */
1758         if( lm->plane != NULL )
1759         {
1760 @@ -699,16 +791,20 @@\r
1761                 ttv = NULL;
1762         }
1763         
1764 +       VectorCopy( dv[ 0 ]->xyz, worldverts[ 0 ] );
1765 +       VectorCopy( dv[ 1 ]->xyz, worldverts[ 1 ] );
1766 +       VectorCopy( dv[ 2 ]->xyz, worldverts[ 2 ] );
1767 +       
1768         /* map the vertexes */
1769 -       MapSingleLuxel( lm, info, dv[ 0 ], plane, 1, stv, ttv );
1770 -       MapSingleLuxel( lm, info, dv[ 1 ], plane, 1, stv, ttv );
1771 -       MapSingleLuxel( lm, info, dv[ 2 ], plane, 1, stv, ttv );
1772 +       MapSingleLuxel( lm, info, dv[ 0 ], plane, 1, stv, ttv, worldverts );
1773 +       MapSingleLuxel( lm, info, dv[ 1 ], plane, 1, stv, ttv, worldverts );
1774 +       MapSingleLuxel( lm, info, dv[ 2 ], plane, 1, stv, ttv, worldverts );
1775         
1776         /* 2002-11-20: prefer axial triangle edges */
1777         if( mapNonAxial )
1778         {
1779                 /* subdivide the triangle */
1780 -               MapTriangle_r( lm, info, dv, plane, stv, ttv );
1781 +               MapTriangle_r( lm, info, dv, plane, stv, ttv, worldverts );
1782                 return qtrue;
1783         }
1784         
1785 @@ -730,7 +826,7 @@\r
1786                         dv2[ 2 ] = dv[ (i + 1) % 3 ];
1787                         
1788                         /* map the degenerate triangle */
1789 -                       MapTriangle_r( lm, info, dv2, plane, stv, ttv );
1790 +                       MapTriangle_r( lm, info, dv2, plane, stv, ttv, worldverts );
1791                 }
1792         }
1793         
1794 @@ -792,8 +888,8 @@\r
1795         LerpDrawVert( dv[ max + 2 ], dv[ (max + 3) % 4 ], &mid[ 1 ] );
1796         
1797         /* map the vertexes */
1798 -       MapSingleLuxel( lm, info, &mid[ 0 ], plane, 1, stv, ttv );
1799 -       MapSingleLuxel( lm, info, &mid[ 1 ], plane, 1, stv, ttv );
1800 +       MapSingleLuxel( lm, info, &mid[ 0 ], plane, 1, stv, ttv, NULL );
1801 +       MapSingleLuxel( lm, info, &mid[ 1 ], plane, 1, stv, ttv, NULL );
1802         
1803         /* 0 and 2 */
1804         if( max == 0 )
1805 @@ -848,7 +944,6 @@\r
1806         vec4_t                  plane;
1807         vec3_t                  *stv, *ttv, stvStatic[ 4 ], ttvStatic[ 4 ];
1808         
1809 -       
1810         /* get plane if possible */
1811         if( lm->plane != NULL )
1812         {
1813 @@ -878,18 +973,16 @@\r
1814         }
1815         
1816         /* map the vertexes */
1817 -       MapSingleLuxel( lm, info, dv[ 0 ], plane, 1, stv, ttv );
1818 -       MapSingleLuxel( lm, info, dv[ 1 ], plane, 1, stv, ttv );
1819 -       MapSingleLuxel( lm, info, dv[ 2 ], plane, 1, stv, ttv );
1820 -       MapSingleLuxel( lm, info, dv[ 3 ], plane, 1, stv, ttv );
1821 +       MapSingleLuxel( lm, info, dv[ 0 ], plane, 1, stv, ttv, NULL );
1822 +       MapSingleLuxel( lm, info, dv[ 1 ], plane, 1, stv, ttv, NULL );
1823 +       MapSingleLuxel( lm, info, dv[ 2 ], plane, 1, stv, ttv, NULL );
1824 +       MapSingleLuxel( lm, info, dv[ 3 ], plane, 1, stv, ttv, NULL );
1825         
1826         /* subdivide the quad */
1827         MapQuad_r( lm, info, dv, plane, stv, ttv );
1828         return qtrue;
1829  }
1830  
1831 -
1832 -
1833  /*
1834  MapRawLightmap()
1835  maps the locations, normals, and pvs clusters for a raw lightmap
1836 @@ -941,7 +1034,7 @@\r
1837                 num = lightSurfaces[ lm->firstLightSurface + n ];
1838                 ds = &bspDrawSurfaces[ num ];
1839                 info = &surfaceInfos[ num ];
1840 -               
1841 +
1842                 /* bail if no lightmap to calculate */
1843                 if( info->lm != lm )
1844                 {
1845 @@ -1173,7 +1266,7 @@\r
1846                                         continue;
1847                                 
1848                                 /* map the fake vert */
1849 -                               MapSingleLuxel( lm, NULL, &fake, lm->plane, pass, NULL, NULL );
1850 +                               MapSingleLuxel( lm, NULL, &fake, lm->plane, pass, NULL, NULL, NULL );
1851                         }
1852                 }
1853         }
1854 @@ -1596,7 +1689,6 @@\r
1855         
1856         VectorSubtract( origin2, origin, originVecs[ 0 ] );
1857         //%     VectorSubtract( normal2, normal, normalVecs[ 0 ] );
1858 -       
1859         /* calulate y vector */
1860         if( (y < (lm->sh - 1) && bx >= 0.0f) || (y == 0 && bx <= 0.0f) )
1861         {
1862 @@ -1660,7 +1752,6 @@\r
1863         float           biasDirs[ 4 ][ 2 ] = { { -1.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f }, { 1.0f, 1.0f } };
1864         vec3_t          color, total;
1865         
1866 -       
1867         /* limit check */
1868         if( lightLuxel[ 3 ] >= lightSamples )
1869                 return;
1870 @@ -1693,7 +1784,6 @@\r
1871                 VectorCopy( normal[ b ], trace->normal );
1872                 
1873                 /* sample light */
1874 -
1875                 LightContributionToSample( trace );
1876                 
1877                 /* add to totals (fixme: make contrast function) */
1878 @@ -1768,7 +1858,6 @@\r
1879         trace_t                         trace;
1880         float                           stackLightLuxels[ STACK_LL_SIZE ];
1881         
1882 -       
1883         /* bail if this number exceeds the number of raw lightmaps */
1884         if( rawLightmapNum >= numRawLightmaps )
1885                 return;
1886 @@ -1904,7 +1993,7 @@\r
1887                                 else
1888                                 {
1889                                         VectorCopy( ambientColor, luxel );
1890 -                                       if( deluxemap )
1891 +                                       if( deluxemap)
1892                                                 VectorScale( normal, 0.00390625f, deluxel );
1893                                         luxel[ 3 ] = 1.0f;
1894                                 }
1895 @@ -1963,28 +2052,39 @@\r
1896                                         deluxel = SUPER_DELUXEL( x, y );
1897                                         origin = SUPER_ORIGIN( x, y );
1898                                         normal = SUPER_NORMAL( x, y );
1899 -                                       
1900 -                                       /* set contribution count */
1901 -                                       lightLuxel[ 3 ] = 1.0f;
1902 -                                       
1903 -                                       /* setup trace */
1904 -                                       trace.cluster = *cluster;
1905 -                                       VectorCopy( origin, trace.origin );
1906 -                                       VectorCopy( normal, trace.normal );
1907 -                                       
1908 -                                       /* get light for this sample */
1909 -                                       LightContributionToSample( &trace );
1910 -                                       VectorCopy( trace.color, lightLuxel );
1911 -                                       
1912 -                                       /* add to count */
1913 -                                       if( trace.color[ 0 ] || trace.color[ 1 ] || trace.color[ 2 ] )
1914 +
1915 +                                       ////////// 27's temp hack for testing edge clipping ////
1916 +                                       if( origin[0]==0 && origin[1]==0 && origin[2]==0 )
1917 +                                       {
1918 +                                               lightLuxel[ 1 ] = 255;
1919 +                                               lightLuxel[ 3 ] = 1.0f;
1920                                                 totalLighted++;
1921 +                                       }
1922 +                                       else
1923 +                                       {
1924 +                                               /* set contribution count */
1925 +                                               lightLuxel[ 3 ] = 1.0f;
1926 +                                               
1927 +                                               /* setup trace */
1928 +                                               trace.cluster = *cluster;
1929 +                                               VectorCopy( origin, trace.origin );
1930 +                                               VectorCopy( normal, trace.normal );
1931 +                                               
1932 +                                               /* get light for this sample */
1933 +                                               LightContributionToSample( &trace );
1934 +                                               VectorCopy( trace.color, lightLuxel );
1935 +                                               
1936 +                                               /* add to count */
1937 +                                               if( trace.color[ 0 ] || trace.color[ 1 ] || trace.color[ 2 ] )
1938 +                                                       totalLighted++;
1939 +                                       }
1940                                         
1941                                         /* add to light direction map (fixme: use luxel normal as starting point for deluxel?) */
1942                                         if( deluxemap )
1943                                         {
1944 +                                               /* vortex: use noShadow color */
1945                                                 /* color to grayscale (photoshop rgb weighting) */
1946 -                                               brightness = trace.color[ 0 ] * 0.3f + trace.color[ 1 ] * 0.59f + trace.color[ 2 ] * 0.11f;
1947 +                                               brightness = trace.colorNoShadow[ 0 ] * 0.3f + trace.colorNoShadow[ 1 ] * 0.59f + trace.colorNoShadow[ 2 ] * 0.11f;
1948                                                 brightness *= (1.0 / 255.0);
1949                                                 VectorScale( trace.direction, brightness, trace.direction );
1950                                                 VectorAdd( deluxel, trace.direction, deluxel );
1951 @@ -2222,6 +2322,38 @@\r
1952         /* free light list */
1953         FreeTraceLights( &trace );
1954         
1955 +       /* floodlight pass */
1956 +       FloodlightIlluminateLightmap(lm);
1957 +
1958 +       if (debugnormals)
1959 +       {
1960 +               for( lightmapNum = 0; lightmapNum < MAX_LIGHTMAPS; lightmapNum++ )
1961 +               {
1962 +                       /* early out */
1963 +                       if( lm->superLuxels[ lightmapNum ] == NULL )
1964 +                               continue;
1965 +                       
1966 +                       for( y = 0; y < lm->sh; y++ )
1967 +                       {
1968 +                               for( x = 0; x < lm->sw; x++ )
1969 +                               {
1970 +                                       /* get cluster */
1971 +                                       cluster = SUPER_CLUSTER( x, y );
1972 +                                       //%     if( *cluster < 0 )
1973 +                                       //%             continue;
1974 +                                       
1975 +                                       /* get particulars */
1976 +                                       luxel = SUPER_LUXEL( lightmapNum, x, y );
1977 +                                       normal = SUPER_NORMAL (  x, y );
1978 +               
1979 +                                       luxel[0]=(normal[0]*127)+127;
1980 +                                       luxel[1]=(normal[1]*127)+127;
1981 +                                       luxel[2]=(normal[2]*127)+127;
1982 +                               }
1983 +                       }
1984 +               }
1985 +       }
1986 +       
1987         /*      -----------------------------------------------------------------
1988                 dirt pass
1989                 ----------------------------------------------------------------- */
1990 @@ -2263,7 +2395,7 @@\r
1991         /* -----------------------------------------------------------------
1992            filter pass
1993            ----------------------------------------------------------------- */
1994 -       
1995 +
1996         /* walk lightmaps */
1997         for( lightmapNum = 0; lightmapNum < MAX_LIGHTMAPS; lightmapNum++ )
1998         {
1999 @@ -3112,7 +3244,7 @@\r
2000         int                     i, x, y, z, x1, y1, z1;
2001         light_t         *light, *light2, **owner;
2002         bspLeaf_t       *leaf;
2003 -       vec3_t          origin, dir, mins, maxs, nullVector = { 0, 0, 0 };
2004 +       vec3_t          origin, dir, mins, maxs;
2005         float           radius, intensity;
2006         light_t         *buckets[ 256 ];
2007         
2008 @@ -3587,7 +3719,430 @@\r
2009         CreateTraceLightsForBounds( mins, maxs, normal, info->numSurfaceClusters, &surfaceClusters[ info->firstSurfaceCluster ], LIGHT_SURFACES, trace );
2010  }
2011  
2012 +/////////////////////////////////////////////////////////////
2013  
2014 +#define FLOODLIGHT_CONE_ANGLE                  88      /* degrees */
2015 +#define FLOODLIGHT_NUM_ANGLE_STEPS             16
2016 +#define FLOODLIGHT_NUM_ELEVATION_STEPS 4
2017 +#define FLOODLIGHT_NUM_VECTORS                 (FLOODLIGHT_NUM_ANGLE_STEPS * FLOODLIGHT_NUM_ELEVATION_STEPS)
2018  
2019 +static vec3_t  floodVectors[ FLOODLIGHT_NUM_VECTORS ];
2020 +static int             numFloodVectors = 0;
2021  
2022 +void SetupFloodLight( void )
2023 +{
2024 +       int             i, j;
2025 +       float   angle, elevation, angleStep, elevationStep;
2026 +       const char      *value;
2027 +       double v1,v2,v3,v4,v5;
2028 +       
2029 +       /* note it */
2030 +       Sys_FPrintf( SYS_VRB, "--- SetupFloodLight ---\n" );
2031 +       
2032 +       /* calculate angular steps */
2033 +       angleStep = DEG2RAD( 360.0f / FLOODLIGHT_NUM_ANGLE_STEPS );
2034 +       elevationStep = DEG2RAD( FLOODLIGHT_CONE_ANGLE / FLOODLIGHT_NUM_ELEVATION_STEPS );
2035 +       
2036 +       /* iterate angle */
2037 +       angle = 0.0f;
2038 +       for( i = 0, angle = 0.0f; i < FLOODLIGHT_NUM_ANGLE_STEPS; i++, angle += angleStep )
2039 +       {
2040 +               /* iterate elevation */
2041 +               for( j = 0, elevation = elevationStep * 0.5f; j < FLOODLIGHT_NUM_ELEVATION_STEPS; j++, elevation += elevationStep )
2042 +               {
2043 +                       floodVectors[ numFloodVectors ][ 0 ] = sin( elevation ) * cos( angle );
2044 +                       floodVectors[ numFloodVectors ][ 1 ] = sin( elevation ) * sin( angle );
2045 +                       floodVectors[ numFloodVectors ][ 2 ] = cos( elevation );
2046 +                       numFloodVectors++;
2047 +               }
2048 +       }
2049 +       
2050 +       /* emit some statistics */
2051 +       Sys_FPrintf( SYS_VRB, "%9d numFloodVectors\n", numFloodVectors );
2052  
2053 +    /* floodlight */
2054 +       value = ValueForKey( &entities[ 0 ], "_floodlight" );
2055 +       
2056 +       if( value[ 0 ] != '\0' )
2057 +       {
2058 +               v1=v2=v3=0;
2059 +               v4=floodlightDistance;
2060 +               v5=floodlightIntensity;
2061 +               
2062 +               sscanf( value, "%lf %lf %lf %lf %lf", &v1, &v2, &v3, &v4, &v5);
2063 +               
2064 +               floodlightRGB[0]=v1;
2065 +               floodlightRGB[1]=v2;
2066 +               floodlightRGB[2]=v3;
2067 +               
2068 +               if (VectorLength(floodlightRGB)==0)
2069 +               {
2070 +                       VectorSet(floodlightRGB,240,240,255);
2071 +               }
2072 +               
2073 +               if (v4<1) v4=1024;
2074 +               if (v5<1) v5=128;
2075 +               
2076 +               floodlightDistance = v4;
2077 +               floodlightIntensity = v5;
2078 +    
2079 +               floodlighty = qtrue;
2080 +               Sys_Printf( "FloodLighting enabled via worldspawn _floodlight key.\n" );
2081 +       }
2082 +       else
2083 +       {
2084 +               VectorSet(floodlightRGB,240,240,255);
2085 +               //floodlighty = qtrue;
2086 +               //Sys_Printf( "FloodLighting enabled via worldspawn _floodlight key.\n" );
2087 +       }
2088 +       VectorNormalize(floodlightRGB,floodlightRGB);
2089 +}
2090 +
2091 +/*
2092 +FloodLightForSample()
2093 +calculates floodlight value for a given sample
2094 +once again, kudos to the dirtmapping coder
2095 +*/
2096 +
2097 +float FloodLightForSample( trace_t *trace , float floodLightDistance, qboolean floodLightLowQuality)
2098 +{
2099 +       int             i;
2100 +       float   d;
2101 +       float   contribution;
2102 +       int     sub = 0;
2103 +       float   gatherLight, outLight;
2104 +       vec3_t  normal, worldUp, myUp, myRt, direction, displacement;
2105 +       float   dd;
2106 +       int     vecs = 0;
2107
2108 +       gatherLight=0;
2109 +       /* dummy check */
2110 +       //if( !dirty )
2111 +       //      return 1.0f;
2112 +       if( trace == NULL || trace->cluster < 0 )
2113 +               return 0.0f;
2114 +       
2115 +
2116 +       /* setup */
2117 +       dd = floodLightDistance;
2118 +       VectorCopy( trace->normal, normal );
2119 +       
2120 +       /* check if the normal is aligned to the world-up */
2121 +       if( normal[ 0 ] == 0.0f && normal[ 1 ] == 0.0f )
2122 +       {
2123 +               if( normal[ 2 ] == 1.0f )               
2124 +               {
2125 +                       VectorSet( myRt, 1.0f, 0.0f, 0.0f );
2126 +                       VectorSet( myUp, 0.0f, 1.0f, 0.0f );
2127 +               }
2128 +               else if( normal[ 2 ] == -1.0f )
2129 +               {
2130 +                       VectorSet( myRt, -1.0f, 0.0f, 0.0f );
2131 +                       VectorSet( myUp,  0.0f, 1.0f, 0.0f );
2132 +               }
2133 +       }
2134 +       else
2135 +       {
2136 +               VectorSet( worldUp, 0.0f, 0.0f, 1.0f );
2137 +               CrossProduct( normal, worldUp, myRt );
2138 +               VectorNormalize( myRt, myRt );
2139 +               CrossProduct( myRt, normal, myUp );
2140 +               VectorNormalize( myUp, myUp );
2141 +       }
2142 +
2143 +       /* vortex: optimise floodLightLowQuality a bit */
2144 +       if ( floodLightLowQuality == qtrue )
2145 +    {
2146 +               /* iterate through ordered vectors */
2147 +               for( i = 0; i < numFloodVectors; i++ )
2148 +                       if (rand()%10 != 0 ) continue;
2149 +       }
2150 +       else
2151 +       {
2152 +               /* iterate through ordered vectors */
2153 +               for( i = 0; i < numFloodVectors; i++ )
2154 +               {
2155 +                       vecs++;
2156 +                
2157 +                       /* transform vector into tangent space */
2158 +                       direction[ 0 ] = myRt[ 0 ] * floodVectors[ i ][ 0 ] + myUp[ 0 ] * floodVectors[ i ][ 1 ] + normal[ 0 ] * floodVectors[ i ][ 2 ];
2159 +                       direction[ 1 ] = myRt[ 1 ] * floodVectors[ i ][ 0 ] + myUp[ 1 ] * floodVectors[ i ][ 1 ] + normal[ 1 ] * floodVectors[ i ][ 2 ];
2160 +                       direction[ 2 ] = myRt[ 2 ] * floodVectors[ i ][ 0 ] + myUp[ 2 ] * floodVectors[ i ][ 1 ] + normal[ 2 ] * floodVectors[ i ][ 2 ];
2161 +
2162 +                       /* set endpoint */
2163 +                       VectorMA( trace->origin, dd, direction, trace->end );
2164 +
2165 +                       //VectorMA( trace->origin, 1, direction, trace->origin );
2166 +                               
2167 +                       SetupTrace( trace );
2168 +                       /* trace */
2169 +                       TraceLine( trace );
2170 +                       contribution=1;
2171 +
2172 +                       if (trace->compileFlags & C_SKY )
2173 +                       {
2174 +                               contribution=1.0f;
2175 +                       }
2176 +                       else if ( trace->opaque )
2177 +                       {
2178 +                               VectorSubtract( trace->hit, trace->origin, displacement );
2179 +                               d=VectorLength( displacement );
2180 +
2181 +                               // d=trace->distance;            
2182 +                               //if (d>256) gatherDirt+=1;
2183 +                               contribution=d/dd;
2184 +                               if (contribution>1) contribution=1.0f; 
2185 +                    
2186 +                               //gatherDirt += 1.0f - ooDepth * VectorLength( displacement );
2187 +                       }
2188 +                
2189 +                       gatherLight+=contribution;
2190 +               }
2191 +       }
2192 +   
2193 +       /* early out */
2194 +       if( gatherLight <= 0.0f )
2195 +               return 0.0f;
2196 +       
2197 +       sub=vecs;
2198 +
2199 +       if (sub<1) sub=1;
2200 +       gatherLight/=(sub);
2201 +
2202 +       outLight=gatherLight;
2203 +       if( outLight > 1.0f )
2204 +               outLight = 1.0f;
2205 +       
2206 +       /* return to sender */
2207 +       return outLight;
2208 +}
2209 +
2210 +/*
2211 +FloodLightRawLightmap
2212 +lighttracer style ambient occlusion light hack.
2213 +Kudos to the dirtmapping author for most of this source.
2214 +VorteX: modified to floodlight up custom surfaces (q3map_floodLight)
2215 +VorteX: fixed problems with deluxemapping
2216 +*/
2217 +
2218 +// floodlight pass on a lightmap
2219 +void FloodLightRawLightmapPass( rawLightmap_t *lm , vec3_t lmFloodLightRGB, float lmFloodLightIntensity, float lmFloodLightDistance, qboolean lmFloodLightLowQuality, float floodlightDirectionScale)
2220 +{
2221 +       int                                     i, x, y, *cluster;
2222 +       float                           *origin, *normal, *floodlight, floodLightAmount;
2223 +       surfaceInfo_t           *info;
2224 +       trace_t                         trace;
2225 +       // int sx, sy;
2226 +       // float samples, average, *floodlight2;
2227 +       
2228 +       memset(&trace,0,sizeof(trace_t));
2229 +
2230 +       /* setup trace */
2231 +       trace.testOcclusion = qtrue;
2232 +       trace.forceSunlight = qfalse;
2233 +       trace.twoSided = qtrue;
2234 +       trace.recvShadows = lm->recvShadows;
2235 +       trace.numSurfaces = lm->numLightSurfaces;
2236 +       trace.surfaces = &lightSurfaces[ lm->firstLightSurface ];
2237 +       trace.inhibitRadius = DEFAULT_INHIBIT_RADIUS;
2238 +       trace.testAll = qfalse;
2239 +       trace.distance = 1024;
2240 +       
2241 +       /* twosided lighting (may or may not be a good idea for lightmapped stuff) */
2242 +       //trace.twoSided = qfalse;
2243 +       for( i = 0; i < trace.numSurfaces; i++ )
2244 +       {
2245 +               /* get surface */
2246 +               info = &surfaceInfos[ trace.surfaces[ i ] ];
2247 +               
2248 +               /* check twosidedness */
2249 +               if( info->si->twoSided )
2250 +               {
2251 +                       trace.twoSided = qtrue;
2252 +                       break;
2253 +               }
2254 +       }
2255 +       
2256 +       /* gather floodlight */
2257 +       for( y = 0; y < lm->sh; y++ )
2258 +       {
2259 +               for( x = 0; x < lm->sw; x++ )
2260 +               {
2261 +                       /* get luxel */
2262 +                       cluster = SUPER_CLUSTER( x, y );
2263 +                       origin = SUPER_ORIGIN( x, y );
2264 +                       normal = SUPER_NORMAL( x, y );
2265 +                       floodlight = SUPER_FLOODLIGHT( x, y );
2266 +                       
2267 +                       /* set default dirt */
2268 +                       *floodlight = 0.0f;
2269 +                       
2270 +                       /* only look at mapped luxels */
2271 +                       if( *cluster < 0 )
2272 +                               continue;
2273 +                       
2274 +                       /* copy to trace */
2275 +                       trace.cluster = *cluster;
2276 +                       VectorCopy( origin, trace.origin );
2277 +                       VectorCopy( normal, trace.normal );
2278 +   
2279 +                       /* get floodlight */
2280 +                       floodLightAmount = FloodLightForSample( &trace , lmFloodLightDistance, lmFloodLightLowQuality)*lmFloodLightIntensity;
2281 +                       
2282 +                       /* add floodlight */
2283 +                       floodlight[0] += lmFloodLightRGB[0]*floodLightAmount;
2284 +                       floodlight[1] += lmFloodLightRGB[1]*floodLightAmount;
2285 +                       floodlight[2] += lmFloodLightRGB[2]*floodLightAmount;
2286 +                       floodlight[3] += floodlightDirectionScale;
2287 +               }
2288 +       }
2289 +       
2290 +       /* testing no filtering */
2291 +       return;
2292 +
2293 +#if 0
2294 +       
2295 +       /* filter "dirt" */
2296 +       for( y = 0; y < lm->sh; y++ )
2297 +       {
2298 +               for( x = 0; x < lm->sw; x++ )
2299 +               {
2300 +                       /* get luxel */
2301 +                       cluster = SUPER_CLUSTER( x, y );
2302 +                       floodlight = SUPER_FLOODLIGHT(x, y );
2303 +                       
2304 +                       /* filter dirt by adjacency to unmapped luxels */
2305 +                       average = *floodlight;
2306 +                       samples = 1.0f;
2307 +                       for( sy = (y - 1); sy <= (y + 1); sy++ )
2308 +                       {
2309 +                               if( sy < 0 || sy >= lm->sh )
2310 +                                       continue;
2311 +                               
2312 +                               for( sx = (x - 1); sx <= (x + 1); sx++ )
2313 +                               {
2314 +                                       if( sx < 0 || sx >= lm->sw || (sx == x && sy == y) )
2315 +                                               continue;
2316 +                                       
2317 +                                       /* get neighboring luxel */
2318 +                                       cluster = SUPER_CLUSTER( sx, sy );
2319 +                                       floodlight2 = SUPER_FLOODLIGHT( sx, sy );
2320 +                                       if( *cluster < 0 || *floodlight2 <= 0.0f )
2321 +                                               continue;
2322 +                                       
2323 +                                       /* add it */
2324 +                                       average += *floodlight2;
2325 +                                       samples += 1.0f;
2326 +                               }
2327 +                               
2328 +                               /* bail */
2329 +                               if( samples <= 0.0f )
2330 +                                       break;
2331 +                       }
2332 +                       
2333 +                       /* bail */
2334 +                       if( samples <= 0.0f )
2335 +                               continue;
2336 +                       
2337 +                       /* scale dirt */
2338 +                       *floodlight = average / samples;
2339 +               }
2340 +       }
2341 +#endif
2342 +}
2343 +
2344 +void FloodLightRawLightmap( int rawLightmapNum )
2345 +{
2346 +       rawLightmap_t           *lm;
2347 +
2348 +       /* bail if this number exceeds the number of raw lightmaps */
2349 +       if( rawLightmapNum >= numRawLightmaps )
2350 +               return;
2351 +       /* get lightmap */
2352 +       lm = &rawLightmaps[ rawLightmapNum ];
2353 +
2354 +       /* global pass */
2355 +       if (floodlighty && floodlightIntensity)
2356 +               FloodLightRawLightmapPass(lm, floodlightRGB, floodlightIntensity, floodlightDistance, floodlight_lowquality, 0);
2357 +
2358 +       /* custom pass */
2359 +       if (lm->floodlightIntensity)
2360 +       {
2361 +               FloodLightRawLightmapPass(lm, lm->floodlightRGB, lm->floodlightIntensity, lm->floodlightDistance, qfalse, lm->floodlightDirectionScale);
2362 +               numSurfacesFloodlighten += 1;
2363 +       }
2364 +}
2365 +
2366 +void FloodlightRawLightmaps()
2367 +{
2368 +       Sys_Printf( "--- FloodlightRawLightmap ---\n" );
2369 +       numSurfacesFloodlighten = 0;
2370 +       RunThreadsOnIndividual( numRawLightmaps, qtrue, FloodLightRawLightmap );
2371 +       Sys_Printf( "%9d custom lightmaps floodlighted\n", numSurfacesFloodlighten );
2372 +}
2373 +
2374 +/*
2375 +FloodLightIlluminate()
2376 +illuminate floodlight into lightmap luxels
2377 +*/
2378 +
2379 +void FloodlightIlluminateLightmap( rawLightmap_t *lm )
2380 +{
2381 +       float                           *luxel, *floodlight, *deluxel, *normal;
2382 +       int                                     *cluster;
2383 +       float                           brightness;
2384 +       vec3_t                          lightvector;
2385 +       int                                     x, y, lightmapNum;
2386 +
2387 +       /* walk lightmaps */
2388 +       for( lightmapNum = 0; lightmapNum < MAX_LIGHTMAPS; lightmapNum++ )
2389 +       {
2390 +               /* early out */
2391 +               if( lm->superLuxels[ lightmapNum ] == NULL )
2392 +                       continue;
2393 +
2394 +               /* apply floodlight to each luxel */
2395 +               for( y = 0; y < lm->sh; y++ )
2396 +               {
2397 +                       for( x = 0; x < lm->sw; x++ )
2398 +                       {
2399 +                               /* get floodlight */
2400 +                               floodlight = SUPER_FLOODLIGHT( x, y );
2401 +                               if (!floodlight[0] && !floodlight[1] && !floodlight[2])
2402 +                                       continue;
2403 +                                               
2404 +                               /* get cluster */
2405 +                               cluster = SUPER_CLUSTER( x, y );
2406 +
2407 +                               /* only process mapped luxels */
2408 +                               if( *cluster < 0 )
2409 +                                       continue;
2410 +
2411 +                               /* get particulars */
2412 +                               luxel = SUPER_LUXEL( lightmapNum, x, y );
2413 +                               deluxel = SUPER_DELUXEL( x, y );
2414 +
2415 +                               /* add to lightmap */
2416 +                               luxel[0]+=floodlight[0];
2417 +                               luxel[1]+=floodlight[1];
2418 +                               luxel[2]+=floodlight[2];
2419 +
2420 +                               if (luxel[3]==0) luxel[3]=1;
2421 +
2422 +                               /* add to deluxemap */
2423 +                               if (deluxemap && floodlight[3] > 0)
2424 +                               {
2425 +                                       normal = SUPER_NORMAL( x, y );
2426 +                                       brightness = floodlight[ 0 ] * 0.3f + floodlight[ 1 ] * 0.59f + floodlight[ 2 ] * 0.11f;
2427 +                                       brightness *= ( 1.0f / 255.0f ) * floodlight[3];
2428 +                                       VectorScale( normal, brightness, lightvector );
2429 +                                       VectorAdd( deluxel, lightvector, deluxel );
2430 +                               }
2431 +                       }
2432 +               }
2433 +       }
2434 +}
2435 +
2436 +
2437 +
2438 +
2439 Index: lightmaps_ydnar.c\r
2440 ===================================================================\r
2441 --- lightmaps_ydnar.c   (revision 158)\r
2442 +++ lightmaps_ydnar.c   (working copy)\r
2443 @@ -414,6 +414,12 @@\r
2444                 lm->superNormals = safe_malloc( size );
2445         memset( lm->superNormals, 0, size );
2446         
2447 +       /* allocate floodlight map storage */
2448 +       size = lm->sw * lm->sh * SUPER_FLOODLIGHT_SIZE * sizeof( float );
2449 +       if( lm->superFloodLight == NULL )
2450 +               lm->superFloodLight = safe_malloc( size );
2451 +       memset( lm->superFloodLight, 0, size );
2452 +       
2453         /* allocate cluster map storage */
2454         size = lm->sw * lm->sh * sizeof( int );
2455         if( lm->superClusters == NULL )
2456 @@ -1087,17 +1093,25 @@\r
2457                 /* allocate a new raw lightmap */
2458                 lm = &rawLightmaps[ numRawLightmaps ];
2459                 numRawLightmaps++;
2460 -               
2461 +       
2462                 /* set it up */
2463                 lm->splotchFix = info->si->splotchFix;
2464                 lm->firstLightSurface = numLightSurfaces;
2465                 lm->numLightSurfaces = 0;
2466 -               lm->sampleSize = info->sampleSize;
2467 -               lm->actualSampleSize = info->sampleSize;
2468 +               /* vortex: multiply lightmap sample size by -samplescale */
2469 +               if (sampleScale > 0)
2470 +                       lm->sampleSize = info->sampleSize*sampleScale;
2471 +               else
2472 +                       lm->sampleSize = info->sampleSize;
2473 +               lm->actualSampleSize = lm->sampleSize;
2474                 lm->entityNum = info->entityNum;
2475                 lm->recvShadows = info->recvShadows;
2476                 lm->brightness = info->si->lmBrightness;
2477                 lm->filterRadius = info->si->lmFilterRadius;
2478 +               VectorCopy(info->si->floodlightRGB, lm->floodlightRGB);
2479 +               lm->floodlightDistance = info->si->floodlightDistance;
2480 +               lm->floodlightIntensity = info->si->floodlightIntensity;
2481 +               lm->floodlightDirectionScale = info->si->floodlightDirectionScale;
2482                 VectorCopy( info->axis, lm->axis );
2483                 lm->plane = info->plane;        
2484                 VectorCopy( info->mins, lm->mins );
2485 @@ -2254,7 +2268,6 @@\r
2486         char                            *rgbGenValues[ 256 ];
2487         char                            *alphaGenValues[ 256 ];
2488         
2489 -       
2490         /* note it */
2491         Sys_Printf( "--- StoreSurfaceLightmaps ---\n");
2492         
2493 @@ -2269,7 +2282,7 @@\r
2494            ----------------------------------------------------------------- */
2495         
2496         /* note it */
2497 -       Sys_FPrintf( SYS_VRB, "Subsampling..." );
2498 +       Sys_Printf( "Subsampling..." );
2499         
2500         /* walk the list of raw lightmaps */
2501         numUsed = 0;
2502 @@ -2437,11 +2450,11 @@\r
2503                                         /* get luxels */
2504                                         luxel = SUPER_LUXEL( lightmapNum, x, y );
2505                                         deluxel = SUPER_DELUXEL( x, y );
2506 -                                       
2507 +
2508                                         /* copy light direction */
2509                                         if( deluxemap && lightmapNum == 0 )
2510                                                 VectorCopy( deluxel, dirSample );
2511 -                                       
2512 +
2513                                         /* is this a valid sample? */
2514                                         if( luxel[ 3 ] > 0.0f )
2515                                         {
2516 @@ -2521,7 +2534,7 @@\r
2517                                         /* store the sample in the bsp luxels */
2518                                         bspLuxel = BSP_LUXEL( lightmapNum, x, y );
2519                                         bspDeluxel = BSP_DELUXEL( x, y );
2520 -                                       
2521 +
2522                                         VectorAdd( bspLuxel, sample, bspLuxel );
2523                                         if( deluxemap && lightmapNum == 0 )
2524                                                 VectorAdd( bspDeluxel, dirSample, bspDeluxel );
2525 @@ -2562,7 +2575,7 @@\r
2526                                         }
2527                                 }
2528                         }
2529 -                       
2530 +
2531                         /* wrap bsp luxels if necessary */
2532                         if( lm->wrap[ 0 ] )
2533                         {
2534 @@ -2604,15 +2617,144 @@\r
2535                         }
2536                 }
2537         }
2538 -       
2539 +
2540         /* -----------------------------------------------------------------
2541 +          convert modelspace deluxemaps to tangentspace
2542 +          ----------------------------------------------------------------- */
2543 +       /* note it */
2544 +       if( !bouncing )
2545 +       {
2546 +               if( deluxemap && deluxemode == 1)
2547 +               {
2548 +                       vec3_t  worldUp, myNormal, myTangent, myBinormal;
2549 +                       float dist;
2550 +
2551 +                       Sys_Printf( "converting..." );
2552 +
2553 +                       for( i = 0; i < numRawLightmaps; i++ )
2554 +                       {
2555 +                               /* get lightmap */
2556 +                               lm = &rawLightmaps[ i ];
2557 +
2558 +                               /* walk lightmap samples */
2559 +                               for( y = 0; y < lm->sh; y++ )
2560 +                               {
2561 +                                       for( x = 0; x < lm->sw; x++ )
2562 +                                       {
2563 +                                               /* get normal and deluxel */
2564 +                                               normal = SUPER_NORMAL(x, y);
2565 +                                               cluster = SUPER_CLUSTER(x, y);
2566 +                                               bspDeluxel = BSP_DELUXEL( x, y );
2567 +                                               deluxel = SUPER_DELUXEL( x, y ); 
2568 +
2569 +                                               /* get normal */
2570 +                                               VectorSet( myNormal, normal[0], normal[1], normal[2] );
2571 +               
2572 +                                               /* get tangent vectors */
2573 +                                               if( myNormal[ 0 ] == 0.0f && myNormal[ 1 ] == 0.0f )
2574 +                                               {
2575 +                                                       if( myNormal[ 2 ] == 1.0f )             
2576 +                                                       {
2577 +                                                               VectorSet( myTangent, 1.0f, 0.0f, 0.0f );
2578 +                                                               VectorSet( myBinormal, 0.0f, 1.0f, 0.0f );
2579 +                                                       }
2580 +                                                       else if( myNormal[ 2 ] == -1.0f )
2581 +                                                       {
2582 +                                                               VectorSet( myTangent, -1.0f, 0.0f, 0.0f );
2583 +                                                               VectorSet( myBinormal,  0.0f, 1.0f, 0.0f );
2584 +                                                       }
2585 +                                               }
2586 +                                               else
2587 +                                               {
2588 +                                                       VectorSet( worldUp, 0.0f, 0.0f, 1.0f );
2589 +                                                       CrossProduct( myNormal, worldUp, myTangent );
2590 +                                                       VectorNormalize( myTangent, myTangent );
2591 +                                                       CrossProduct( myTangent, myNormal, myBinormal );
2592 +                                                       VectorNormalize( myBinormal, myBinormal );
2593 +                                               }
2594 +
2595 +                                               /* project onto plane */
2596 +                                               dist = -DotProduct(myTangent, myNormal); 
2597 +                                               VectorMA(myTangent, dist, myNormal, myTangent);
2598 +                                               dist = -DotProduct(myBinormal, myNormal); 
2599 +                                               VectorMA(myBinormal, dist, myNormal, myBinormal);
2600 +
2601 +                                               /* renormalize */
2602 +                                               VectorNormalize( myTangent, myTangent );
2603 +                                               VectorNormalize( myBinormal, myBinormal );
2604 +
2605 +                                               /* convert modelspace deluxel to tangentspace */
2606 +                                               dirSample[0] = bspDeluxel[0];
2607 +                                               dirSample[1] = bspDeluxel[1];
2608 +                                               dirSample[2] = bspDeluxel[2];
2609 +                                               VectorNormalize(dirSample, dirSample);
2610 +
2611 +                                               /* fix tangents to world matrix */
2612 +                                               if (myNormal[0] > 0 || myNormal[1] < 0 || myNormal[2] < 0)
2613 +                                                       VectorNegate(myTangent, myTangent);
2614 +
2615 +                                               /* build tangentspace vectors */
2616 +                                               bspDeluxel[0] = DotProduct(dirSample, myTangent);
2617 +                                               bspDeluxel[1] = DotProduct(dirSample, myBinormal);
2618 +                                               bspDeluxel[2] = DotProduct(dirSample, myNormal);
2619 +                                       }
2620 +                               }
2621 +                       }
2622 +               }
2623 +       }
2624 +
2625 +       /* -----------------------------------------------------------------
2626 +          blend lightmaps
2627 +          ----------------------------------------------------------------- */
2628 +
2629 +#ifdef sdfsdfwq312323
2630 +       /* note it */
2631 +       Sys_Printf( "blending..." );
2632 +
2633 +       for( i = 0; i < numRawLightmaps; i++ )
2634 +       {
2635 +               vec3_t  myColor;
2636 +               float myBrightness;
2637 +
2638 +               /* get lightmap */
2639 +               lm = &rawLightmaps[ i ];
2640 +
2641 +               /* walk individual lightmaps */
2642 +               for( lightmapNum = 0; lightmapNum < MAX_LIGHTMAPS; lightmapNum++ )
2643 +               {
2644 +                       /* early outs */
2645 +                       if( lm->superLuxels[ lightmapNum ] == NULL )
2646 +                               continue;
2647 +
2648 +                       /* walk lightmap samples */
2649 +                       for( y = 0; y < lm->sh; y++ )
2650 +                       {
2651 +                               for( x = 0; x < lm->sw; x++ )
2652 +                               {
2653 +                                       /* get luxel */
2654 +                                       bspLuxel = BSP_LUXEL( lightmapNum, x, y );
2655 +
2656 +                                       /* get color */
2657 +                                       VectorNormalize(bspLuxel, myColor);
2658 +                                       myBrightness = VectorLength(bspLuxel);
2659 +                                       myBrightness *= (1 / 127.0f);
2660 +                                       myBrightness = myBrightness*myBrightness;
2661 +                                       myBrightness *= 127.0f;
2662 +                                       VectorScale(myColor, myBrightness, bspLuxel);
2663 +                               }
2664 +                       }
2665 +               }
2666 +       }
2667 +#endif
2668 +
2669 +       /* -----------------------------------------------------------------
2670            collapse non-unique lightmaps
2671            ----------------------------------------------------------------- */
2672         
2673         if( noCollapse == qfalse && deluxemap == qfalse )
2674         {
2675                 /* note it */
2676 -               Sys_FPrintf( SYS_VRB, "collapsing..." );
2677 +               Sys_Printf( "collapsing..." );
2678                 
2679                 /* set all twin refs to null */
2680                 for( i = 0; i < numRawLightmaps; i++ )
2681 @@ -2674,13 +2816,13 @@\r
2682                         }
2683                 }
2684         }
2685 -       
2686 +
2687         /* -----------------------------------------------------------------
2688            sort raw lightmaps by shader
2689            ----------------------------------------------------------------- */
2690         
2691         /* note it */
2692 -       Sys_FPrintf( SYS_VRB, "sorting..." );
2693 +       Sys_Printf( "sorting..." );
2694         
2695         /* allocate a new sorted list */
2696         if( sortLightmaps == NULL )
2697 @@ -2696,7 +2838,7 @@\r
2698            ----------------------------------------------------------------- */
2699         
2700         /* note it */
2701 -       Sys_FPrintf( SYS_VRB, "allocating..." );
2702 +       Sys_Printf( "allocating..." );
2703         
2704         /* kill all existing output lightmaps */
2705         if( outLightmaps != NULL )
2706 @@ -2749,7 +2891,7 @@\r
2707            ----------------------------------------------------------------- */
2708         
2709         /* note it */
2710 -       Sys_FPrintf( SYS_VRB, "storing..." );
2711 +       Sys_Printf( "storing..." );
2712         
2713         /* count the bsp lightmaps and allocate space */
2714         if( bspLightBytes != NULL )
2715 @@ -2817,7 +2959,7 @@\r
2716         }
2717         
2718         if( numExtLightmaps > 0 )
2719 -               Sys_FPrintf( SYS_VRB, "\n" );
2720 +               Sys_Printf( SYS_VRB, "\n" );
2721         
2722         /* delete unused external lightmaps */
2723         for( i = numExtLightmaps; i; i++ )
2724 @@ -2836,7 +2978,7 @@\r
2725            ----------------------------------------------------------------- */
2726         
2727         /* note it */
2728 -       Sys_FPrintf( SYS_VRB, "projecting..." );
2729 +       Sys_Printf( "projecting..." );
2730         
2731         /* walk the list of surfaces */
2732         for( i = 0; i < numBSPDrawSurfaces; i++ )
2733 @@ -3108,7 +3250,7 @@\r
2734         }
2735         
2736         /* finish */
2737 -       Sys_FPrintf( SYS_VRB, "done.\n" );
2738 +       Sys_Printf( "done.\n" );
2739         
2740         /* calc num stored */
2741         numStored = numBSPLightBytes / 3;
2742 Index: main.c\r
2743 ===================================================================\r
2744 --- main.c      (revision 158)\r
2745 +++ main.c      (working copy)\r
2746 @@ -604,7 +604,7 @@\r
2747         
2748         /* set exit call */
2749         atexit( ExitQ3Map );
2750 -       
2751 +
2752         /* read general options first */
2753         for( i = 1; i < argc; i++ )
2754         {
2755 @@ -680,6 +680,10 @@\r
2756         
2757         /* ydnar: new path initialization */
2758         InitPaths( &argc, argv );
2759 +
2760 +       /* set game options */
2761 +       if (!patchSubdivisions)
2762 +               patchSubdivisions = game->patchSubdivisions;
2763         
2764         /* check if we have enough options left to attempt something */
2765         if( argc < 2 )
2766 Index: map.c\r
2767 ===================================================================\r
2768 --- map.c       (revision 158)\r
2769 +++ map.c       (working copy)\r
2770 @@ -1515,14 +1515,18 @@\r
2771         /* get explicit shadow flags */
2772         GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows );
2773         
2774 +       /* vortex: added _ls key (short name of lightmapscale) */
2775         /* ydnar: get lightmap scaling value for this entity */
2776         if( strcmp( "", ValueForKey( mapEnt, "lightmapscale" ) ) ||
2777 -               strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) )
2778 +               strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) || 
2779 +               strcmp( "", ValueForKey( mapEnt, "_ls" ) ) )
2780         {
2781                 /* get lightmap scale from entity */
2782                 lightmapScale = FloatForKey( mapEnt, "lightmapscale" );
2783                 if( lightmapScale <= 0.0f )
2784                         lightmapScale = FloatForKey( mapEnt, "_lightmapscale" );
2785 +               if( lightmapScale <= 0.0f )
2786 +                       lightmapScale = FloatForKey( mapEnt, "_ls" );
2787                 if( lightmapScale > 0.0f )
2788                         Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale );
2789         }
2790 Index: mesh.c\r
2791 ===================================================================\r
2792 --- mesh.c      (revision 158)\r
2793 +++ mesh.c      (working copy)\r
2794 @@ -563,7 +563,7 @@\r
2795         }
2796         
2797         /* keep chopping */
2798 -       for( iterations; iterations > 0; iterations-- )
2799 +       for( ; iterations > 0; iterations-- )
2800         {
2801                 /* horizontal subdivisions */
2802                 for( j = 0; j + 2 < out.width; j += 4 )
2803 Index: model.c\r
2804 ===================================================================\r
2805 --- model.c     (revision 158)\r
2806 +++ model.c     (working copy)\r
2807 @@ -266,7 +266,7 @@\r
2808                         continue;
2809                 
2810                 /* fix the surface's normals */
2811 -               PicoFixSurfaceNormals( surface );
2812 +               //PicoFixSurfaceNormals( surface );
2813                 
2814                 /* allocate a surface (ydnar: gs mods) */
2815                 ds = AllocDrawSurface( SURFACE_TRIANGLES );
2816 @@ -521,7 +521,15 @@\r
2817                                                 else
2818                                                         free( buildBrush );
2819                                         }
2820 +                                       else
2821 +                                       {
2822 +                                               Sys_Printf( "WARNING: Model %s unable to generate brush - Case 1.\n", name );  
2823 +                                       }
2824                                 }
2825 +                               else
2826 +                               {
2827 +                                       Sys_Printf( "WARNING: Model %s unable to generate brush - Case 2.\n", name );  
2828 +                               }  
2829                         }
2830                 }
2831         }
2832 @@ -566,8 +574,11 @@\r
2833         }
2834         
2835         /* get lightmap scale */
2836 +       /* vortex: added _ls key (short name of lightmapscale) */
2837         baseLightmapScale = FloatForKey( e, "_lightmapscale" );
2838         if( baseLightmapScale <= 0.0f )
2839 +               baseLightmapScale = FloatForKey( e, "_ls" );
2840 +       if( baseLightmapScale <= 0.0f )
2841                 baseLightmapScale = 0.0f;
2842         
2843         /* walk the entity list */
2844 @@ -688,8 +699,11 @@\r
2845                         celShader = NULL;
2846                 
2847                 /* get lightmap scale */
2848 +               /* vortex: added _ls key (short name of lightmapscale) */
2849                 lightmapScale = FloatForKey( e2, "_lightmapscale" );
2850                 if( lightmapScale <= 0.0f )
2851 +                       lightmapScale = FloatForKey( e2, "_ls" );
2852 +               if( lightmapScale <= 0.0f )
2853                         lightmapScale = baseLightmapScale;
2854                 
2855                 /* insert the model */
2856 Index: patch.c\r
2857 ===================================================================\r
2858 --- patch.c     (revision 158)\r
2859 +++ patch.c     (working copy)\r
2860 @@ -227,7 +227,6 @@\r
2861         float                   longestCurve;
2862         int                             maxIterations;
2863         
2864 -       
2865         MatchToken( "{" );
2866         
2867         /* get texture */
2868 Index: path_init.c\r
2869 ===================================================================\r
2870 --- path_init.c (revision 158)\r
2871 +++ path_init.c (working copy)\r
2872 @@ -383,7 +383,7 @@\r
2873         /* remove processed arguments */
2874         for( i = 0, j = 0, k = 0; i < *argc && j < *argc; i++, j++ )
2875         {
2876 -               for( j; j < *argc && argv[ j ] == NULL; j++ );
2877 +               for( ; j < *argc && argv[ j ] == NULL; j++ );
2878                 argv[ i ] = argv[ j ];
2879                 if( argv[ i ] != NULL )
2880                         k++;
2881 Index: q3map2.h\r
2882 ===================================================================\r
2883 --- q3map2.h    (revision 158)\r
2884 +++ q3map2.h    (working copy)\r
2885 @@ -35,8 +35,8 @@\r
2886  
2887  
2888  /* version */
2889 -#define Q3MAP_VERSION  "2.5.17"
2890 -#define Q3MAP_MOTD             "Last one turns the lights off"
2891 +#define Q3MAP_VERSION  "2.5.17 base : FS_20g base : R5"
2892 +#define Q3MAP_MOTD             "Sorry, it doesn't match my furniture."
2893  
2894  
2895  
2896 @@ -235,6 +235,7 @@\r
2897  #define LIGHT_FAST_TEMP                        512
2898  #define LIGHT_FAST_ACTUAL              (LIGHT_FAST | LIGHT_FAST_TEMP)
2899  #define LIGHT_NEGATIVE                 1024
2900 +#define LIGHT_UNNORMALIZED             2048    /* vortex: do not normalize _color */
2901  
2902  #define LIGHT_SUN_DEFAULT              (LIGHT_ATTEN_ANGLE | LIGHT_GRID | LIGHT_SURFACES)
2903  #define LIGHT_AREA_DEFAULT             (LIGHT_ATTEN_ANGLE | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES)        /* q3a and wolf are the same */
2904 @@ -267,6 +268,7 @@\r
2905  #define SUPER_NORMAL_SIZE              4
2906  #define SUPER_DELUXEL_SIZE             3
2907  #define BSP_DELUXEL_SIZE               3
2908 +#define SUPER_FLOODLIGHT_SIZE  4
2909  
2910  #define VERTEX_LUXEL( s, v )   (vertexLuxels[ s ] + ((v) * VERTEX_LUXEL_SIZE))
2911  #define RAD_VERTEX_LUXEL( s, v )(radVertexLuxels[ s ] + ((v) * VERTEX_LUXEL_SIZE))
2912 @@ -279,9 +281,8 @@\r
2913  #define SUPER_ORIGIN( x, y )   (lm->superOrigins + ((((y) * lm->sw) + (x)) * SUPER_ORIGIN_SIZE))
2914  #define SUPER_NORMAL( x, y )   (lm->superNormals + ((((y) * lm->sw) + (x)) * SUPER_NORMAL_SIZE))
2915  #define SUPER_DIRT( x, y )             (lm->superNormals + ((((y) * lm->sw) + (x)) * SUPER_NORMAL_SIZE) + 3)   /* stash dirtyness in normal[ 3 ] */
2916 +#define SUPER_FLOODLIGHT(x, y )        (lm->superFloodLight + ((((y) * lm->sw) + (x)) * SUPER_FLOODLIGHT_SIZE))
2917  
2918 -
2919 -
2920  /* -------------------------------------------------------------------------------
2921  
2922  abstracted bsp file
2923 @@ -543,7 +544,16 @@\r
2924         qboolean                        wolfLight;                                              /* when true, lights work like wolf q3map  */
2925         int                                     lightmapSize;                                   /* bsp lightmap width/height */
2926         float                           lightmapGamma;                                  /* default lightmap gamma */
2927 +       float                           lightmapExposure;                               /* default lightmap exposure */
2928         float                           lightmapCompensate;                             /* default lightmap compensate value */
2929 +       float                           gridScale;                                              /* vortex: default lightgrid scale (affects both directional and ambient spectres) */
2930 +       float                           gridAmbientScale;                               /* vortex: default lightgrid ambient spectre scale */
2931 +       qboolean                        noStyles;                                               /* use lightstyles hack or not */
2932 +       qboolean                        keepLights;                                             /* keep light entities on bsp */
2933 +       int                                     patchSubdivisions;                              /* default patch subdivisions tolerance */
2934 +       qboolean                        patchShadows;                                   /* patch casting enabled */
2935 +       qboolean                        deluxeMap;                                              /* compile deluxemaps */
2936 +       int                                     deluxeMode;                                             /* deluxemap mode (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
2937         char                            *bspIdent;                                              /* 4-letter bsp file prefix */
2938         int                                     bspVersion;                                             /* bsp version to use */
2939         qboolean                        lumpSwap;                                               /* cod-style len/ofs order */
2940 @@ -662,6 +672,7 @@\r
2941         char                            *backShader;                                    /* for surfaces that generate different front and back passes */
2942         char                            *cloneShader;                                   /* ydnar: for cloning of a surface */
2943         char                            *remapShader;                                   /* ydnar: remap a shader in final stage */
2944 +       char                            *deprecateShader;                               /* vortex: shader is deprecated and replaced by this on use */
2945  
2946         surfaceModel_t          *surfaceModel;                                  /* ydnar: for distribution of models */
2947         foliage_t                       *foliage;                                               /* ydnar/splash damage: wolf et foliage */
2948 @@ -737,7 +748,13 @@\r
2949         
2950         vec3_t                          color;                                                  /* normalized color */
2951         vec3_t                          averageColor;
2952 -       byte                            lightStyle;
2953 +       byte                            lightStyle;                                     
2954 +
2955 +       /* vortex: per-surface floodlight */
2956 +       float                           floodlightDirectionScale;
2957 +       vec3_t                          floodlightRGB; 
2958 +       float                           floodlightIntensity;
2959 +       float                           floodlightDistance;
2960         
2961         qb_t                            lmMergable;                                             /* ydnar */
2962         int                                     lmCustomWidth, lmCustomHeight;  /* ydnar */
2963 @@ -1013,7 +1030,7 @@\r
2964         int                                     maxIterations;
2965         int                                     patchWidth, patchHeight;
2966         vec3_t                          bounds[ 2 ];
2967 -       
2968 +
2969         /* ydnar/sd: for foliage */
2970         int                                     numFoliageInstances;
2971         
2972 @@ -1061,6 +1078,7 @@\r
2973         int                                     mapEntityNum, firstDrawSurf;
2974         int                                     firstBrush, numBrushes;         /* only valid during BSP compile */
2975         epair_t                         *epairs;
2976 +       qboolean                        forceNormalSmoothing; /* vortex: true if entity has _smoothnormals/_sn/_smooth key */
2977  }
2978  entity_t;
2979  
2980 @@ -1296,7 +1314,8 @@\r
2981         
2982         /* input and output */
2983         vec3_t                          color;                  /* starts out at full color, may be reduced if transparent surfaces are crossed */
2984 -       
2985 +       vec3_t                          colorNoShadow;  /* result color with no shadow casting */
2986 +
2987         /* output */
2988         vec3_t                          hit;
2989         int                                     compileFlags;   /* for determining surface compile flags traced through */
2990 @@ -1367,6 +1386,13 @@\r
2991         int                                             numLightClusters, *lightClusters;
2992         
2993         int                                             sampleSize, actualSampleSize, axisNum;
2994 +
2995 +       /* vortex: per-surface floodlight */
2996 +       float                                   floodlightDirectionScale;
2997 +       vec3_t                                  floodlightRGB; 
2998 +       float                                   floodlightIntensity;
2999 +       float                                   floodlightDistance;
3000 +
3001         int                                             entityNum;
3002         int                                             recvShadows;
3003         vec3_t                                  mins, maxs, axis, origin, *vecs;
3004 @@ -1389,9 +1415,9 @@\r
3005         float                                   *superOrigins;
3006         float                                   *superNormals;
3007         int                                             *superClusters;
3008 -       
3009         float                                   *superDeluxels; /* average light direction */
3010         float                                   *bspDeluxels;
3011 +       float                                   *superFloodLight; /* floodlight color */
3012  }
3013  rawLightmap_t;
3014  
3015 @@ -1421,8 +1447,6 @@\r
3016  }
3017  surfaceInfo_t;
3018  
3019 -
3020 -
3021  /* -------------------------------------------------------------------------------
3022  
3023  prototypes
3024 @@ -1556,6 +1580,7 @@\r
3025  void                                           ParsePatch( qboolean onlyLights );
3026  mesh_t                                         *SubdivideMesh( mesh_t in, float maxError, float minLength );
3027  void                                           PatchMapDrawSurfs( entity_t *e );
3028 +void                                           TriangulatePatchSurface( entity_t *e , mapDrawSurface_t *ds );
3029  
3030  
3031  /* tjunction.c */
3032 @@ -1610,6 +1635,8 @@\r
3033  void                                           AddEntitySurfaceModels( entity_t *e );
3034  int                                                    AddSurfaceModels( mapDrawSurface_t *ds );
3035  void                                           FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree );
3036 +void                                           EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds );
3037 +static void                                    EmitTriangleSurface( mapDrawSurface_t *ds );
3038  
3039  
3040  /* surface_fur.c */
3041 @@ -1627,6 +1654,7 @@\r
3042  void                                           FixMetaTJunctions( void );
3043  void                                           SmoothMetaTriangles( void );
3044  void                                           MergeMetaTriangles( void );
3045 +void                                           EmitMetaStats(); // vortex: print meta statistics even in no-verbose mode
3046  
3047  
3048  /* surface_extra.c */
3049 @@ -1704,6 +1732,12 @@\r
3050  float                                          DirtForSample( trace_t *trace );
3051  void                                           DirtyRawLightmap( int num );
3052  
3053 +void                                           SetupFloodLight();
3054 +void                                           FloodlightRawLightmaps();
3055 +void                                           FloodlightIlluminateLightmap( rawLightmap_t *lm );
3056 +float                                          FloodLightForSample( trace_t *trace , float floodLightDistance, qboolean floodLightLowQuality);
3057 +void                                           FloodLightRawLightmap( int num );
3058 +
3059  void                                           IlluminateRawLightmap( int num );
3060  void                                           IlluminateVertexes( int num );
3061  
3062 @@ -1731,7 +1765,6 @@\r
3063  void                                           StitchSurfaceLightmaps( void );
3064  void                                           StoreSurfaceLightmaps( void );
3065  
3066 -
3067  /* image.c */
3068  void                                           ImageFree( image_t *image );
3069  image_t                                                *ImageFind( const char *filename );
3070 @@ -1783,6 +1816,7 @@\r
3071  void                                           UnparseEntities( void );
3072  void                                           PrintEntity( const entity_t *ent );
3073  void                                           SetKeyValue( entity_t *ent, const char *key, const char *value );
3074 +qboolean                                       KeyExists( const entity_t *ent, const char *key ); /* VorteX: check if key exists */
3075  const char                                     *ValueForKey( const entity_t *ent, const char *key );
3076  int                                                    IntForKey( const entity_t *ent, const char *key );
3077  vec_t                                          FloatForKey( const entity_t *ent, const char *key );
3078 @@ -1845,6 +1879,12 @@\r
3079                                                                 ,
3080                                                                 #include "game_qfusion.h"       /* qfusion game */
3081                                                                 ,
3082 +                                                               #include "game_darkplaces.h"    /* vortex: darkplaces q1 engine */
3083 +                                                               ,
3084 +                                                               #include "game_dq.h"    /* vortex: deluxe quake game ( darkplaces q1 engine) */
3085 +                                                               ,
3086 +                                                               #include "game_prophecy.h"      /* vortex: prophecy game ( darkplaces q1 engine) */
3087 +                                                               ,
3088                                                                 { NULL }        /* null game */
3089                                                         };
3090  #endif
3091 @@ -1929,6 +1969,7 @@\r
3092  Q_EXTERN char                          outbase[ 32 ];
3093  
3094  Q_EXTERN int                           sampleSize;                                             /* lightmap sample size in units */
3095 +Q_EXTERN int                           sampleScale;                                    /* vortex: lightmap sample scale (ie quality)*/
3096  
3097  Q_EXTERN int                           mapEntityNum Q_ASSIGN( 0 );
3098  
3099 @@ -2053,6 +2094,7 @@\r
3100  Q_EXTERN qboolean                      wolfLight Q_ASSIGN( qfalse );
3101  Q_EXTERN qboolean                      loMem Q_ASSIGN( qfalse );
3102  Q_EXTERN qboolean                      noStyles Q_ASSIGN( qfalse );
3103 +Q_EXTERN qboolean                      keepLights Q_ASSIGN( qfalse );
3104  
3105  Q_EXTERN int                           sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE );
3106  Q_EXTERN qboolean                      noVertexLighting Q_ASSIGN( qfalse );
3107 @@ -2065,6 +2107,7 @@\r
3108  
3109  Q_EXTERN qboolean                      deluxemap Q_ASSIGN( qfalse );
3110  Q_EXTERN qboolean                      debugDeluxemap Q_ASSIGN( qfalse );
3111 +Q_EXTERN int                           deluxemode Q_ASSIGN( 0 );       /* deluxemap format (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
3112  
3113  Q_EXTERN qboolean                      fast Q_ASSIGN( qfalse );
3114  Q_EXTERN qboolean                      faster Q_ASSIGN( qfalse );
3115 @@ -2098,6 +2141,14 @@\r
3116  Q_EXTERN float                         dirtScale Q_ASSIGN( 1.0f );
3117  Q_EXTERN float                         dirtGain Q_ASSIGN( 1.0f );
3118  
3119 +/* 27: floodlighting */
3120 +Q_EXTERN qboolean                                      debugnormals Q_ASSIGN( qfalse );
3121 +Q_EXTERN qboolean                                      floodlighty Q_ASSIGN( qfalse );
3122 +Q_EXTERN qboolean                                      floodlight_lowquality Q_ASSIGN( qfalse );
3123 +Q_EXTERN vec3_t                                                floodlightRGB;
3124 +Q_EXTERN float                                         floodlightIntensity Q_ASSIGN( 512.0f );
3125 +Q_EXTERN float                                         floodlightDistance Q_ASSIGN( 1024.0f );
3126 +
3127  Q_EXTERN qboolean                      dump Q_ASSIGN( qfalse );
3128  Q_EXTERN qboolean                      debug Q_ASSIGN( qfalse );
3129  Q_EXTERN qboolean                      debugUnused Q_ASSIGN( qfalse );
3130 @@ -2115,9 +2166,14 @@\r
3131  Q_EXTERN float                         skyScale Q_ASSIGN( 1.0f );
3132  Q_EXTERN float                         bounceScale Q_ASSIGN( 0.25f );
3133  
3134 +/* vortex: gridscale and gridambientscale */
3135 +Q_EXTERN float                         gridScale Q_ASSIGN( 1.0f );
3136 +Q_EXTERN float                         gridAmbientScale Q_ASSIGN( 1.0f );
3137 +
3138  /* ydnar: lightmap gamma/compensation */
3139  Q_EXTERN float                         lightmapGamma Q_ASSIGN( 1.0f );
3140  Q_EXTERN float                         lightmapCompensate Q_ASSIGN( 1.0f );
3141 +Q_EXTERN float                         lightmapExposure Q_ASSIGN( 1.0f );
3142  
3143  /* ydnar: for runtime tweaking of falloff tolerance */
3144  Q_EXTERN float                         falloffTolerance Q_ASSIGN( 1.0f );
3145 @@ -2221,6 +2277,9 @@\r
3146  Q_EXTERN int                           numExtLightmaps Q_ASSIGN( 0 );
3147  Q_EXTERN outLightmap_t         *outLightmaps Q_ASSIGN( NULL );
3148  
3149 +/* vortex: per surface floodlight statictics */
3150 +Q_EXTERN int                           numSurfacesFloodlighten Q_ASSIGN( 0 );
3151 +
3152  /* grid points */
3153  Q_EXTERN int                           numRawGridPoints Q_ASSIGN( 0 );
3154  Q_EXTERN rawGridPoint_t                *rawGridPoints Q_ASSIGN( NULL );
3155 Index: shaders.c\r
3156 ===================================================================\r
3157 --- shaders.c   (revision 158)\r
3158 +++ shaders.c   (working copy)\r
3159 @@ -793,8 +793,14 @@\r
3160         }
3161         
3162         if( VectorLength( si->color ) <= 0.0f )
3163 +       {
3164                 ColorNormalize( color, si->color );
3165 -       VectorScale( color, (1.0f / count), si->averageColor );
3166 +               VectorScale( color, (1.0f / count), si->averageColor );
3167 +       }
3168 +       else
3169 +       {
3170 +               VectorCopy( si->color, si->averageColor );
3171 +       }
3172  }
3173  
3174  
3175 @@ -804,13 +810,15 @@\r
3176  finds a shaderinfo for a named shader
3177  */
3178  
3179 +#define MAX_SHADER_DEPRECATION_DEPTH 16
3180 +
3181  shaderInfo_t *ShaderInfoForShader( const char *shaderName )
3182  {
3183         int                             i;
3184 +       int                             deprecationDepth;
3185         shaderInfo_t    *si;
3186         char                    shader[ MAX_QPATH ];
3187 -       
3188 -       
3189 +
3190         /* dummy check */
3191         if( shaderName == NULL || shaderName[ 0 ] == '\0' )
3192         {
3193 @@ -823,11 +831,27 @@\r
3194         StripExtension( shader );
3195         
3196         /* search for it */
3197 +       deprecationDepth = 0;
3198         for( i = 0; i < numShaderInfo; i++ )
3199         {
3200                 si = &shaderInfo[ i ];
3201                 if( !Q_stricmp( shader, si->shader ) )
3202                 {
3203 +                       /* check if shader is deprecated */
3204 +                       if (deprecationDepth < MAX_SHADER_DEPRECATION_DEPTH && si->deprecateShader && si->deprecateShader[ 0 ] )
3205 +                       {
3206 +                               /* override name */
3207 +                               strcpy( shader, si->deprecateShader );
3208 +                               StripExtension( shader );
3209 +                               /* increase deprecation depth */
3210 +                               deprecationDepth++;
3211 +                               if (deprecationDepth == MAX_SHADER_DEPRECATION_DEPTH)
3212 +                                       Sys_Printf("WARNING: Max deprecation depth of %i is reached on shader '%s'\n", MAX_SHADER_DEPRECATION_DEPTH, shader);
3213 +                               /* search again from beginning */
3214 +                               i = -1;
3215 +                               continue;
3216 +                       }
3217 +
3218                         /* load image if necessary */
3219                         if( si->finished == qfalse )
3220                         {
3221 @@ -1340,7 +1364,6 @@\r
3222                                 {
3223                                         surfaceModel_t  *model;
3224                                         
3225 -                                       
3226                                         /* allocate new model and attach it */
3227                                         model = safe_malloc( sizeof( *model ) );
3228                                         memset( model, 0, sizeof( *model ) );
3229 @@ -1465,6 +1488,24 @@\r
3230                                         GetTokenAppend( shaderText, qfalse );
3231                                         si->backsplashDistance = atof( token );
3232                                 }
3233 +
3234 +                               /* q3map_floodLight <r> <g> <b> <diste> <intensity> <light_direction_power> */
3235 +                               else if( !Q_stricmp( token, "q3map_floodLight" ) )
3236 +                               {
3237 +                                       /* get color */
3238 +                                       GetTokenAppend( shaderText, qfalse );
3239 +                                       si->floodlightRGB[ 0 ] = atof( token );
3240 +                                       GetTokenAppend( shaderText, qfalse );
3241 +                                       si->floodlightRGB[ 1 ] = atof( token );
3242 +                                       GetTokenAppend( shaderText, qfalse );
3243 +                                       si->floodlightRGB[ 2 ] = atof( token );
3244 +                                       GetTokenAppend( shaderText, qfalse );
3245 +                                       si->floodlightDistance = atof( token ); 
3246 +                                       GetTokenAppend( shaderText, qfalse );
3247 +                                       si->floodlightIntensity = atof( token ); 
3248 +                                       GetTokenAppend( shaderText, qfalse );
3249 +                                       si->floodlightDirectionScale = atof( token ); 
3250 +                               }
3251                                 
3252                                 /* q3map_lightmapSampleSize <value> */
3253                                 else if( !Q_stricmp( token, "q3map_lightmapSampleSize" ) )
3254 @@ -1590,6 +1631,18 @@\r
3255                                                 strcpy( si->remapShader, token );
3256                                         }
3257                                 }
3258 +
3259 +                               /* q3map_deprecateShader <shader> */
3260 +                               else if( !Q_stricmp( token, "q3map_deprecateShader" ) )
3261 +                               {
3262 +                                       GetTokenAppend( shaderText, qfalse );
3263 +                                       if( token[ 0 ] != '\0' )
3264 +                                       {
3265 +
3266 +                                               si->deprecateShader = safe_malloc( strlen( token ) + 1 );
3267 +                                               strcpy( si->deprecateShader, token );
3268 +                                       }
3269 +                               }
3270                                 
3271                                 /* ydnar: q3map_offset <value> */
3272                                 else if( !Q_stricmp( token, "q3map_offset" ) )
3273 @@ -1896,12 +1949,14 @@\r
3274                                         si->styleMarker = 2;
3275                                 
3276                                 /* ydnar: default to searching for q3map_<surfaceparm> */
3277 -                               else
3278 +#if 0
3279 +                               else
3280                                 {
3281 -                                       //%     Sys_FPrintf( SYS_VRB, "Attempting to match %s with a known surfaceparm\n", token );
3282 +                                       Sys_FPrintf( SYS_VRB, "Attempting to match %s with a known surfaceparm\n", token );
3283                                         if( ApplySurfaceParm( &token[ 6 ], &si->contentFlags, &si->surfaceFlags, &si->compileFlags ) == qfalse )
3284 -                                               ;//%    Sys_Printf( "WARNING: Unknown q3map_* directive \"%s\"\n", token );
3285 +                                               Sys_Printf( "WARNING: Unknown q3map_* directive \"%s\"\n", token );
3286                                 }
3287 +#endif
3288                         }
3289                         
3290                         
3291 Index: surface.c\r
3292 ===================================================================\r
3293 --- surface.c   (revision 158)\r
3294 +++ surface.c   (working copy)\r
3295 @@ -304,7 +304,7 @@\r
3296                 out = &mapDrawSurfs[ i ];
3297                 
3298                 /* walk the surface list again until a proper surface is found */
3299 -               for( j; j < numMapDrawSurfs; j++ )
3300 +               for( ; j < numMapDrawSurfs; j++ )
3301                 {
3302                         /* get in surface */
3303                         in = &mapDrawSurfs[ j ];
3304 @@ -484,7 +484,7 @@\r
3305         
3306         
3307         /* walk the list of surfaces */
3308 -       for( numSurfs; numSurfs > 0; numSurfs--, ds++ )
3309 +       for( ; numSurfs > 0; numSurfs--, ds++ )
3310         {
3311                 /* ignore bogus (or flare) surfaces */
3312                 if( ds->type == SURFACE_BAD || ds->numVerts <= 0 )
3313 @@ -2445,25 +2445,27 @@\r
3314         numSurfacesByType[ ds->type ]++;
3315  }
3316  
3317 -
3318 -
3319  /*
3320  EmitPatchSurface()
3321  emits a bsp patch drawsurface
3322  */
3323  
3324 -void EmitPatchSurface( mapDrawSurface_t *ds )
3325 +void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds )
3326  {
3327         int                                     i, j;
3328         bspDrawSurface_t        *out;
3329         int                                     surfaceFlags, contentFlags;
3330 +       int                                     forcePatchMeta;
3331 +
3332 +       /* vortex: _patchMeta support */
3333 +       forcePatchMeta = IntForKey(e, "_patchMeta" );
3334 +       if (!forcePatchMeta)
3335 +               forcePatchMeta = IntForKey(e, "patchMeta" );
3336         
3337 -       
3338         /* invert the surface if necessary */
3339         if( ds->backSide || ds->shaderInfo->invert )
3340         {
3341                 bspDrawVert_t   *dv1, *dv2, temp;
3342 -               
3343  
3344                 /* walk the verts, flip the normal */
3345                 for( i = 0; i < ds->numVerts; i++ )
3346 @@ -2485,7 +2487,7 @@\r
3347                 /* invert facing */
3348                 VectorScale( ds->lightmapVecs[ 2 ], -1.0f, ds->lightmapVecs[ 2 ] );
3349         }
3350 -       
3351 +
3352         /* allocate a new surface */
3353         if( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS )
3354                 Error( "MAX_MAP_DRAW_SURFS" );
3355 @@ -2493,12 +2495,12 @@\r
3356         ds->outputNum = numBSPDrawSurfaces;
3357         numBSPDrawSurfaces++;
3358         memset( out, 0, sizeof( *out ) );
3359 -       
3360 +
3361         /* set it up */
3362         out->surfaceType = MST_PATCH;
3363         if( debugSurfaces )
3364                 out->shaderNum = EmitShader( "debugsurfaces", NULL, NULL );
3365 -       else if( patchMeta )
3366 +       else if( patchMeta || forcePatchMeta )
3367         {
3368                 /* patch meta requires that we have nodraw patches for collision */
3369                 surfaceFlags = ds->shaderInfo->surfaceFlags;
3370 @@ -2548,8 +2550,6 @@\r
3371         numSurfacesByType[ ds->type ]++;
3372  }
3373  
3374 -
3375 -
3376  /*
3377  OptimizeTriangleSurface() - ydnar
3378  optimizes the vertex/index data in a triangle surface
3379 @@ -2677,8 +2677,7 @@\r
3380  {
3381         int                                             i, temp;
3382         bspDrawSurface_t                *out;
3383 -       
3384 -       
3385 +
3386         /* invert the surface if necessary */
3387         if( ds->backSide || ds->shaderInfo->invert )
3388         {
3389 @@ -2689,15 +2688,15 @@\r
3390                         ds->indexes[ i ] = ds->indexes[ i + 1 ];
3391                         ds->indexes[ i + 1 ] = temp;
3392                 }
3393 -               
3394 +                       
3395                 /* walk the verts, flip the normal */
3396                 for( i = 0; i < ds->numVerts; i++ )
3397                         VectorScale( ds->verts[ i ].normal, -1.0f, ds->verts[ i ].normal );
3398 -               
3399 +                       
3400                 /* invert facing */
3401                 VectorScale( ds->lightmapVecs[ 2 ], -1.0f, ds->lightmapVecs[ 2 ] );
3402         }
3403 -       
3404 +               
3405         /* allocate a new surface */
3406         if( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS )
3407                 Error( "MAX_MAP_DRAW_SURFS" );
3408 @@ -2804,15 +2803,14 @@\r
3409  emits a bsp planar winding (brush face) drawsurface
3410  */
3411  
3412 -static void EmitFaceSurface( mapDrawSurface_t *ds )
3413 +static void EmitFaceSurface(mapDrawSurface_t *ds )
3414  {
3415         /* strip/fan finding was moved elsewhere */
3416         StripFaceSurface( ds );
3417 -       EmitTriangleSurface( ds );
3418 +       EmitTriangleSurface(ds);
3419  }
3420  
3421  
3422 -
3423  /*
3424  MakeDebugPortalSurfs_r() - ydnar
3425  generates drawsurfaces for passable portals in the bsp
3426 @@ -3502,7 +3500,7 @@\r
3427                                 if( refs == 0 )
3428                                         refs = FilterPatchIntoTree( ds, tree );
3429                                 if( refs > 0 )
3430 -                                       EmitPatchSurface( ds );
3431 +                                       EmitPatchSurface( e, ds );
3432                                 break;
3433                         
3434                         /* handle triangle surfaces */
3435 Index: surface_meta.c\r
3436 ===================================================================\r
3437 --- surface_meta.c      (revision 158)\r
3438 +++ surface_meta.c      (working copy)\r
3439 @@ -312,23 +312,41 @@\r
3440  creates triangles from a patch
3441  */
3442  
3443 -void TriangulatePatchSurface( mapDrawSurface_t *ds )
3444 +void TriangulatePatchSurface( entity_t *e , mapDrawSurface_t *ds )
3445  {
3446         int                                     iterations, x, y, pw[ 5 ], r;
3447         mapDrawSurface_t        *dsNew;
3448         mesh_t                          src, *subdivided, *mesh;
3449 -       
3450 -       
3451 +       int                                     forcePatchMeta;
3452 +       int                                     patchQuality;
3453 +       int                                     patchSubdivision;
3454 +
3455 +       /* vortex: _patchMeta, _patchQuality, _patchSubdivide support */
3456 +       forcePatchMeta = IntForKey(e, "_patchMeta" );
3457 +       if (!forcePatchMeta)
3458 +               forcePatchMeta = IntForKey(e, "patchMeta" );
3459 +       patchQuality = IntForKey(e, "_patchQuality" );
3460 +       if (!patchQuality)
3461 +               patchQuality = IntForKey(e, "patchQuality" );
3462 +       if (!patchQuality)
3463 +               patchQuality = 1.0;
3464 +       patchSubdivision = IntForKey(e, "_patchSubdivide" );
3465 +       if (!patchSubdivision)
3466 +               patchSubdivision = IntForKey(e, "patchSubdivide" );
3467 +
3468         /* try to early out */
3469 -       if( ds->numVerts == 0 || ds->type != SURFACE_PATCH || patchMeta == qfalse )
3470 +       if(ds->numVerts == 0 || ds->type != SURFACE_PATCH || ( patchMeta == qfalse && !forcePatchMeta) )
3471                 return;
3472 -       
3473         /* make a mesh from the drawsurf */ 
3474         src.width = ds->patchWidth;
3475         src.height = ds->patchHeight;
3476         src.verts = ds->verts;
3477         //%     subdivided = SubdivideMesh( src, 8, 999 );
3478 -       iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions );
3479 +       if (patchSubdivision)
3480 +               iterations = IterationsForCurve( ds->longestCurve, patchSubdivision );
3481 +       else
3482 +               iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / patchQuality );
3483 +
3484         subdivided = SubdivideMesh2( src, iterations ); //%     ds->maxIterations
3485         
3486         /* fit it to the curve and remove colinear verts on rows/columns */
3487 @@ -599,7 +617,22 @@\r
3488  }
3489  
3490  
3491 +/*
3492 +EmitMetaStatictics
3493 +vortex: prints meta statistics in general output
3494 +*/
3495  
3496 +void EmitMetaStats()
3497 +{
3498 +       Sys_Printf( "--- EmitMetaStats ---\n" );
3499 +       Sys_Printf( "%9d total meta surfaces\n", numMetaSurfaces );
3500 +       Sys_Printf( "%9d stripped surfaces\n", numStripSurfaces );
3501 +       Sys_Printf( "%9d fanned surfaces\n", numFanSurfaces );
3502 +       Sys_Printf( "%9d patch meta surfaces\n", numPatchMetaSurfaces );
3503 +       Sys_Printf( "%9d meta verts\n", numMetaVerts );
3504 +       Sys_Printf( "%9d meta triangles\n", numMetaTriangles );
3505 +}
3506 +
3507  /*
3508  MakeEntityMetaTriangles()
3509  builds meta triangles from brush faces (tristrips and fans)
3510 @@ -652,12 +685,12 @@\r
3511                                 break;
3512                         
3513                         case SURFACE_PATCH:
3514 -                               TriangulatePatchSurface( ds );
3515 +                               TriangulatePatchSurface(e, ds );
3516                                 break;
3517                         
3518                         case SURFACE_TRIANGLES:
3519                                 break;
3520 -                       
3521 +               
3522                         case SURFACE_FORCED_META:
3523                         case SURFACE_META:
3524                                 SurfaceToMetaTriangles( ds );
3525 @@ -972,8 +1005,8 @@\r
3526         vec3_t                  average, diff;
3527         int                             indexes[ MAX_SAMPLES ];
3528         vec3_t                  votes[ MAX_SAMPLES ];
3529 +       const char              *classname;
3530         
3531 -       
3532         /* note it */
3533         Sys_FPrintf( SYS_VRB, "--- SmoothMetaTriangles ---\n" );
3534         
3535 @@ -994,11 +1027,31 @@\r
3536            and set per-vertex smoothing angle */
3537         for( i = 0, tri = &metaTriangles[ i ]; i < numMetaTriangles; i++, tri++ )
3538         {
3539 +               /* vortex: try get smoothing from entity key */
3540 +               shadeAngle = FloatForKey(&entities[tri->entityNum], "_smoothnormals");
3541 +               if (shadeAngle <= 0.0f)
3542 +                       shadeAngle = FloatForKey(&entities[tri->entityNum], "_sn");
3543 +               if (shadeAngle <= 0.0f)
3544 +                       shadeAngle = FloatForKey(&entities[tri->entityNum], "_smooth");
3545 +               if (shadeAngle > 0.0f)
3546 +               {
3547 +                       if (entities[tri->entityNum].forceNormalSmoothing == qfalse)
3548 +                       {
3549 +                               entities[tri->entityNum].forceNormalSmoothing = qtrue;
3550 +                               classname = ValueForKey( &entities[tri->entityNum], "classname" );
3551 +                               Sys_Printf( "Entity %d (%s) has vertex normal smoothing with breaking angle of %3.0f\n", tri->entityNum, classname, shadeAngle );
3552 +                       }
3553 +                       shadeAngle = DEG2RAD( shadeAngle );
3554 +               }
3555 +
3556                 /* get shader for shade angle */
3557 -               if( tri->si->shadeAngleDegrees > 0.0f )
3558 -                       shadeAngle = DEG2RAD( tri->si->shadeAngleDegrees );
3559 -               else
3560 -                       shadeAngle = defaultShadeAngle;
3561 +               if (shadeAngle <= 0.0f)
3562 +               {
3563 +                       if( tri->si->shadeAngleDegrees > 0.0f )
3564 +                               shadeAngle = DEG2RAD( tri->si->shadeAngleDegrees );
3565 +                       else
3566 +                               shadeAngle = defaultShadeAngle;
3567 +               }
3568                 if( shadeAngle > maxShadeAngle )
3569                         maxShadeAngle = shadeAngle;
3570                 
3571 Index: writebsp.c\r
3572 ===================================================================\r
3573 --- writebsp.c  (revision 158)\r
3574 +++ writebsp.c  (working copy)\r
3575 @@ -136,7 +136,6 @@\r
3576         bspLeaf_t               *leaf_p;
3577         brush_t                 *b;
3578         drawSurfRef_t   *dsr;
3579 -       int                             i = 0;
3580  
3581         
3582         /* check limits */
3583 @@ -278,18 +277,19 @@\r
3584  void SetLightStyles( void )
3585  {
3586         int                     i, j, style, numStyles;
3587 -       qboolean        keepLights;
3588         const char      *t;
3589         entity_t        *e;
3590         epair_t         *ep, *next;
3591         char            value[ 10 ];
3592         char            lightTargets[ MAX_SWITCHED_LIGHTS ][ 64 ];
3593         int                     lightStyles[ MAX_SWITCHED_LIGHTS ];
3594 -       
3595 -       
3596 +
3597         /* ydnar: determine if we keep lights in the bsp */
3598 -       t = ValueForKey( &entities[ 0 ], "_keepLights" );
3599 -       keepLights = (t[ 0 ] == '1') ? qtrue : qfalse;
3600 +       if (KeyExists(&entities[ 0 ], "_keepLights") == qtrue)
3601 +       {
3602 +               t = ValueForKey( &entities[ 0 ], "_keepLights" );
3603 +               keepLights = (t[ 0 ] == '1') ? qtrue : qfalse;
3604 +       }
3605         
3606         /* any light that is controlled (has a targetname) must have a unique style number generated for it */
3607         numStyles = 0;