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