]> icculus.org git repositories - divverent/darkplaces.git/blob - r_part.c
fix for uppercase nehahra movie names (oops, 'twas Ender's code).
[divverent/darkplaces.git] / r_part.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "quakedef.h"
22
23 #define MAX_PARTICLES                   4096    // default max # of particles at one
24                                                                                 //  time
25 #define ABSOLUTE_MIN_PARTICLES  512             // no fewer than this no matter what's
26                                                                                 //  on the command line
27
28 int             ramp1[8] = {0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61};
29 int             ramp2[8] = {0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66};
30 int             ramp3[8] = {0x6d, 0x6b, 6, 5, 4, 3};
31
32 int             particletexture;
33 int             smokeparticletexture[8];
34 int             flareparticletexture;
35 int             rainparticletexture;
36 int             bloodcloudparticletexture;
37 int             bubbleparticletexture;
38
39 particle_t      *active_particles, *free_particles;
40
41 particle_t      *particles;
42 int                     r_numparticles;
43
44 vec3_t                  r_pright, r_pup, r_ppn;
45
46 cvar_t r_particles = {"r_particles", "1", true};
47
48 void fractalnoise(char *noise, int size);
49 void fractalnoise_zeroedge(char *noise, int size);
50
51 void R_InitParticleTexture (void)
52 {
53         int             x,y,d,i;
54         float   dx, dy, dz, f, dot;
55         byte    data[32][32][4], noise1[32][32], noise2[32][32];
56         vec3_t  normal, light;
57
58         particletexture = texture_extension_number++;
59     glBindTexture(GL_TEXTURE_2D, particletexture);
60
61         for (x=0 ; x<32 ; x++)
62         {
63                 for (y=0 ; y<32 ; y++)
64                 {
65                         data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
66                         dx = x - 16;
67                         dy = y - 16;
68                         d = (255 - (dx*dx+dy*dy));
69                         if (d < 0) d = 0;
70                         data[y][x][3] = (byte) d;
71                 }
72         }
73         glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
74
75         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
76
77         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
78         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
79
80
81         for (i = 0;i < 8;i++)
82         {
83                 fractalnoise(&noise1[0][0], 32);
84                 fractalnoise(&noise2[0][0], 32);
85                 for (y = 0;y < 32;y++)
86                         for (x = 0;x < 32;x++)
87                         {
88                                 data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
89                                 dx = x - 16;
90                                 dy = y - 16;
91                                 d = noise2[y][x] * 4 - 512;
92                                 if (d > 0)
93                                 {
94                                         if (d > 255)
95                                                 d = 255;
96                                         d = (d * (255 - (int) (dx*dx+dy*dy))) >> 8;
97                                         if (d < 0) d = 0;
98                                         if (d > 255) d = 255;
99                                         data[y][x][3] = (byte) d;
100                                 }
101                                 else
102                                         data[y][x][3] = 0;
103                         }
104
105                 /*
106                 for (x=0 ; x<34 ; x+=2)
107                         for (y=0 ; y<34 ; y+=2)
108                                 data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%32)+192;
109                 for (x=0 ; x<32 ; x+=2)
110                         for (y=0 ; y<32 ; y+=2)
111                         {
112                                 data[y  ][x+1][0] = data[y  ][x+1][1] = data[y  ][x+1][2] = (int) (data[y  ][x  ][0] + data[y  ][x+2][0]) >> 1;
113                                 data[y+1][x  ][0] = data[y+1][x  ][1] = data[y+1][x  ][2] = (int) (data[y  ][x  ][0] + data[y+2][x  ][0]) >> 1;
114                                 data[y+1][x+1][0] = data[y+1][x+1][1] = data[y+1][x+1][2] = (int) (data[y  ][x  ][0] + data[y  ][x+2][0] + data[y+2][x  ][0] + data[y+2][x+2][0]) >> 2;
115                         }
116                 for (x=0 ; x<32 ; x++)
117                 {
118                         for (y=0 ; y<32 ; y++)
119                         {
120                                 //data[y][x][0] = data[y][x][1] = data[y][x][2] = (rand()%192)+32;
121                                 dx = x - 16;
122                                 dy = y - 16;
123                                 d = (255 - (dx*dx+dy*dy));
124                                 if (d < 0) d = 0;
125                                 data[y][x][3] = (byte) d;
126                         }
127                 }
128                 */
129                 smokeparticletexture[i] = texture_extension_number++;
130                 glBindTexture(GL_TEXTURE_2D, smokeparticletexture[i]);
131                 glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
132                 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
133                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
134                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
135         }
136
137         fractalnoise(&noise1[0][0], 32);
138         fractalnoise(&noise2[0][0], 32);
139         for (y = 0;y < 32;y++)
140                 for (x = 0;x < 32;x++)
141                 {
142                         data[y][x][0] = data[y][x][1] = data[y][x][2] = (noise1[y][x] >> 1) + 128;
143                         dx = x - 16;
144                         dy = y - 16;
145                         d = (noise2[y][x] * (255 - (dx*dx+dy*dy))) * (1.0f / 255.0f);
146                         if (d < 0) d = 0;
147                         if (d > 255) d = 255;
148                         data[y][x][3] = (byte) d;
149                 }
150
151         bloodcloudparticletexture = texture_extension_number++;
152         glBindTexture(GL_TEXTURE_2D, bloodcloudparticletexture);
153         glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
154         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
155         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
156         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
157
158         flareparticletexture = texture_extension_number++;
159     glBindTexture(GL_TEXTURE_2D, flareparticletexture);
160
161         for (x=0 ; x<32 ; x++)
162         {
163                 for (y=0 ; y<32 ; y++)
164                 {
165                         data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
166                         dx = x - 16;
167                         dy = y - 16;
168                         d = 2048 / (dx*dx+dy*dy+1) - 32;
169                         d = bound(0, d, 255);
170                         data[y][x][3] = (byte) d;
171                 }
172         }
173         glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
174
175         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
176
177         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
178         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
179
180         rainparticletexture = texture_extension_number++;
181     glBindTexture(GL_TEXTURE_2D, rainparticletexture);
182
183         for (x=0 ; x<32 ; x++)
184         {
185                 for (y=0 ; y<32 ; y++)
186                 {
187                         data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
188                         if (y < 24) // stretch the upper half to make a raindrop
189                         {
190                                 dx = (x - 16)*2;
191                                 dy = (y - 24)*2/3;
192                                 d = (255 - (dx*dx+dy*dy))/2;
193                         }
194                         else
195                         {
196                                 dx = (x - 16)*2;
197                                 dy = (y - 24)*2;
198                                 d = (255 - (dx*dx+dy*dy))/2;
199                         }
200                         if (d < 0) d = 0;
201                         data[y][x][3] = (byte) d;
202                 }
203         }
204         glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
205
206         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
207
208         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
209         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
210
211         bubbleparticletexture = texture_extension_number++;
212     glBindTexture(GL_TEXTURE_2D, bubbleparticletexture);
213
214         light[0] = 1;light[1] = 1;light[2] = 1;
215         VectorNormalize(light);
216         for (x=0 ; x<32 ; x++)
217         {
218                 for (y=0 ; y<32 ; y++)
219                 {
220                         data[y][x][0] = data[y][x][1] = data[y][x][2] = 255;
221                         dx = x * (1.0 / 16.0) - 1.0;
222                         dy = y * (1.0 / 16.0) - 1.0;
223                         if (dx*dx+dy*dy < 1) // it does hit the sphere
224                         {
225                                 dz = 1 - (dx*dx+dy*dy);
226                                 f = 0;
227                                 // back side
228                                 normal[0] = dx;normal[1] = dy;normal[2] = dz;
229                                 VectorNormalize(normal);
230                                 dot = DotProduct(normal, light);
231                                 if (dot > 0.5) // interior reflection
232                                         f += ((dot *  2) - 1);
233                                 else if (dot < -0.5) // exterior reflection
234                                         f += ((dot * -2) - 1);
235                                 // front side
236                                 normal[0] = dx;normal[1] = dy;normal[2] = -dz;
237                                 VectorNormalize(normal);
238                                 dot = DotProduct(normal, light);
239                                 if (dot > 0.5) // interior reflection
240                                         f += ((dot *  2) - 1);
241                                 else if (dot < -0.5) // exterior reflection
242                                         f += ((dot * -2) - 1);
243                                 f *= 64;
244                                 f = bound(0, f, 255);
245                                 data[y][x][3] = (byte) f;
246                         }
247                         else
248                                 data[y][x][3] = 0;
249                 }
250         }
251         glTexImage2D (GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
252
253         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
254
255         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
256         glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
257 }
258
259 /*
260 ===============
261 R_InitParticles
262 ===============
263 */
264 void R_InitParticles (void)
265 {
266         int             i;
267
268         i = COM_CheckParm ("-particles");
269
270         if (i)
271         {
272                 r_numparticles = (int)(atoi(com_argv[i+1]));
273                 if (r_numparticles < ABSOLUTE_MIN_PARTICLES)
274                         r_numparticles = ABSOLUTE_MIN_PARTICLES;
275         }
276         else
277         {
278                 r_numparticles = MAX_PARTICLES;
279         }
280
281         particles = (particle_t *) Hunk_AllocName (r_numparticles * sizeof(particle_t), "particles");
282
283         Cvar_RegisterVariable (&r_particles);
284         R_InitParticleTexture ();
285 }
286
287 /*
288 ===============
289 R_EntityParticles
290 ===============
291 */
292
293 #define NUMVERTEXNORMALS        162
294 extern  float   r_avertexnormals[NUMVERTEXNORMALS][3];
295 vec3_t  avelocities[NUMVERTEXNORMALS];
296 float   beamlength = 16;
297 vec3_t  avelocity = {23, 7, 3};
298 float   partstep = 0.01;
299 float   timescale = 0.01;
300
301 void R_EntityParticles (entity_t *ent)
302 {
303         int                     count;
304         int                     i;
305         particle_t      *p;
306         float           angle;
307         float           sr, sp, sy, cr, cp, cy;
308         vec3_t          forward;
309         float           dist;
310         if (!r_particles.value) return; // LordHavoc: particles are optional
311         
312         dist = 64;
313         count = 50;
314
315 if (!avelocities[0][0])
316 {
317 for (i=0 ; i<NUMVERTEXNORMALS*3 ; i++)
318 avelocities[0][i] = (rand()&255) * 0.01;
319 }
320
321
322         for (i=0 ; i<NUMVERTEXNORMALS ; i++)
323         {
324                 angle = cl.time * avelocities[i][0];
325                 sy = sin(angle);
326                 cy = cos(angle);
327                 angle = cl.time * avelocities[i][1];
328                 sp = sin(angle);
329                 cp = cos(angle);
330                 angle = cl.time * avelocities[i][2];
331                 sr = sin(angle);
332                 cr = cos(angle);
333         
334                 forward[0] = cp*cy;
335                 forward[1] = cp*sy;
336                 forward[2] = -sp;
337
338                 if (!free_particles)
339                         return;
340                 p = free_particles;
341                 free_particles = p->next;
342                 p->next = active_particles;
343                 active_particles = p;
344
345                 p->texnum = flareparticletexture;
346                 p->scale = 2;
347                 p->alpha = 255;
348                 p->die = cl.time + 0.01;
349                 p->color = 0x6f;
350                 p->type = pt_explode;
351                 
352                 p->org[0] = ent->origin[0] + r_avertexnormals[i][0]*dist + forward[0]*beamlength;                       
353                 p->org[1] = ent->origin[1] + r_avertexnormals[i][1]*dist + forward[1]*beamlength;                       
354                 p->org[2] = ent->origin[2] + r_avertexnormals[i][2]*dist + forward[2]*beamlength;                       
355         }
356 }
357
358
359 /*
360 ===============
361 R_ClearParticles
362 ===============
363 */
364 void R_ClearParticles (void)
365 {
366         int             i;
367         
368         free_particles = &particles[0];
369         active_particles = NULL;
370
371         for (i=0 ;i<r_numparticles ; i++)
372                 particles[i].next = &particles[i+1];
373         particles[r_numparticles-1].next = NULL;
374 }
375
376
377 void R_ReadPointFile_f (void)
378 {
379         FILE    *f;
380         vec3_t  org;
381         int             r;
382         int             c;
383         particle_t      *p;
384         char    name[MAX_OSPATH];
385         
386         sprintf (name,"maps/%s.pts", sv.name);
387
388         COM_FOpenFile (name, &f, false);
389         if (!f)
390         {
391                 Con_Printf ("couldn't open %s\n", name);
392                 return;
393         }
394         
395         Con_Printf ("Reading %s...\n", name);
396         c = 0;
397         for ( ;; )
398         {
399                 r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
400                 if (r != 3)
401                         break;
402                 c++;
403                 
404                 if (!free_particles)
405                 {
406                         Con_Printf ("Not enough free particles\n");
407                         break;
408                 }
409                 p = free_particles;
410                 free_particles = p->next;
411                 p->next = active_particles;
412                 active_particles = p;
413                 
414                 p->texnum = particletexture;
415                 p->scale = 2;
416                 p->alpha = 255;
417                 p->die = 99999;
418                 p->color = (-c)&15;
419                 p->type = pt_static;
420                 VectorCopy (vec3_origin, p->vel);
421                 VectorCopy (org, p->org);
422         }
423
424         fclose (f);
425         Con_Printf ("%i points read\n", c);
426 }
427
428 /*
429 ===============
430 R_ParseParticleEffect
431
432 Parse an effect out of the server message
433 ===============
434 */
435 void R_ParseParticleEffect (void)
436 {
437         vec3_t          org, dir;
438         int                     i, count, msgcount, color;
439         
440         for (i=0 ; i<3 ; i++)
441                 org[i] = MSG_ReadCoord ();
442         for (i=0 ; i<3 ; i++)
443                 dir[i] = MSG_ReadChar () * (1.0/16);
444         msgcount = MSG_ReadByte ();
445         color = MSG_ReadByte ();
446
447 if (msgcount == 255)
448         count = 1024;
449 else
450         count = msgcount;
451         
452         R_RunParticleEffect (org, dir, color, count);
453 }
454         
455 /*
456 ===============
457 R_ParticleExplosion
458
459 ===============
460 */
461 void R_ParticleExplosion (vec3_t org, int smoke)
462 {
463         int                     i, j;
464         particle_t      *p;
465         if (!r_particles.value) return; // LordHavoc: particles are optional
466         
467         for (i=0 ; i<1024 ; i++)
468         {
469                 if (!free_particles)
470                         return;
471                 p = free_particles;
472                 free_particles = p->next;
473                 p->next = active_particles;
474                 active_particles = p;
475
476                 p->texnum = smokeparticletexture[rand()&7];
477                 p->scale = lhrandom(1,3);
478                 p->alpha = rand()&255;
479                 p->die = cl.time + 5;
480                 p->color = ramp1[0];
481                 p->ramp = lhrandom(0, 4);
482 //              if (i & 1)
483 //                      p->type = pt_explode;
484 //              else
485 //                      p->type = pt_explode2;
486                 p->color = ramp1[rand()&7];
487                 p->type = pt_fallfadespark;
488                 for (j=0 ; j<3 ; j++)
489                 {
490                         p->org[j] = org[j] + ((rand()&15)-8);
491                         p->vel[j] = lhrandom(-192, 192);
492                 }
493                 p->vel[2] += 160;
494         }
495
496         if (smoke)
497         {
498                 for (i=0 ; i<32 ; i++)
499                 {
500                         if (!free_particles)
501                                 return;
502                         p = free_particles;
503                         free_particles = p->next;
504                         p->next = active_particles;
505                         active_particles = p;
506
507                         p->texnum = smokeparticletexture[rand()&7];
508                         p->scale = 12;
509                         p->alpha = 80;
510                         p->die = cl.time + 2;
511                         p->type = pt_smoke;
512                         p->color = (rand()&7) + 8;
513                         for (j=0 ; j<3 ; j++)
514                         {
515                                 p->org[j] = org[j] + ((rand()%96)-48);
516                                 p->vel[j] = (rand()&63)-32;
517                         }
518                 }
519         }
520 }
521
522 /*
523 ===============
524 R_ParticleExplosion2
525
526 ===============
527 */
528 void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength)
529 {
530         int                     i, j;
531         particle_t      *p;
532         int                     colorMod = 0;
533         if (!r_particles.value) return; // LordHavoc: particles are optional
534
535         for (i=0; i<512; i++)
536         {
537                 if (!free_particles)
538                         return;
539                 p = free_particles;
540                 free_particles = p->next;
541                 p->next = active_particles;
542                 active_particles = p;
543
544                 p->texnum = smokeparticletexture[rand()&7];
545                 p->scale = 1.5;
546                 p->alpha = 255;
547                 p->die = cl.time + 0.3;
548                 p->color = colorStart + (colorMod % colorLength);
549                 colorMod++;
550
551                 p->type = pt_blob;
552                 for (j=0 ; j<3 ; j++)
553                 {
554                         p->org[j] = org[j] + ((rand()&15)-8);
555                         p->vel[j] = lhrandom(-128, 128);
556                 }
557         }
558 }
559
560 /*
561 ===============
562 R_BlobExplosion
563
564 ===============
565 */
566 void R_BlobExplosion (vec3_t org)
567 {
568         int                     i, j;
569         particle_t      *p;
570         if (!r_particles.value) return; // LordHavoc: particles are optional
571         
572         for (i=0 ; i<1024 ; i++)
573         {
574                 if (!free_particles)
575                         return;
576                 p = free_particles;
577                 free_particles = p->next;
578                 p->next = active_particles;
579                 active_particles = p;
580
581                 p->texnum = smokeparticletexture[rand()&7];
582                 p->scale = 2;
583                 p->alpha = 255;
584                 p->die = cl.time + 1 + (rand()&8)*0.05;
585
586                 if (i & 1)
587                 {
588                         p->type = pt_blob;
589                         p->color = 66 + rand()%6;
590                         for (j=0 ; j<3 ; j++)
591                         {
592                                 p->org[j] = org[j] + ((rand()%32)-16);
593                                 p->vel[j] = lhrandom(-128, 128);
594                         }
595                 }
596                 else
597                 {
598                         p->type = pt_blob2;
599                         p->color = 150 + rand()%6;
600                         for (j=0 ; j<3 ; j++)
601                         {
602                                 p->org[j] = org[j] + ((rand()%32)-16);
603                                 p->vel[j] = lhrandom(-128, 128);
604                         }
605                 }
606                 p->vel[0] *= 0.25;
607                 p->vel[1] *= 0.25;
608         }
609 }
610
611 /*
612 ===============
613 R_RunParticleEffect
614
615 ===============
616 */
617 void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count)
618 {
619         int                     j;
620         particle_t      *p;
621         if (!r_particles.value) return; // LordHavoc: particles are optional
622         
623         if (count == 1024)
624         {
625                 R_ParticleExplosion(org, false);
626                 return;
627         }
628         while (count)
629         {
630                 if (!free_particles)
631                         return;
632                 p = free_particles;
633                 free_particles = p->next;
634                 p->next = active_particles;
635                 active_particles = p;
636                 if (count & 3)
637                 {
638                         p->alpha = (count & 3) * 16 + (rand()&15);
639                         count &= ~3;
640                 }
641                 else
642                 {
643                         p->alpha = 64;
644                         count -= 4;
645                 }
646
647                 p->texnum = particletexture;
648                 p->scale = 6;
649                 p->die = cl.time + 1; //lhrandom(0.1, 0.5);
650                 p->color = (color&~7) + (rand()&7);
651                 p->type = pt_fade; //static; //slowgrav;
652                 for (j=0 ; j<3 ; j++)
653                 {
654                         p->org[j] = org[j] + ((rand()&15)-8);
655                         p->vel[j] = dir[j]*15;// + (rand()%300)-150;
656                 }
657         }
658 }
659
660 // LordHavoc: added this for spawning sparks/dust (which have strong gravity)
661 /*
662 ===============
663 R_SparkShower
664
665 ===============
666 */
667 void R_SparkShower (vec3_t org, vec3_t dir, int count, int type)
668 {
669         int                     i, j;
670         particle_t      *p;
671         if (!r_particles.value) return; // LordHavoc: particles are optional
672
673         if (!free_particles)
674                 return;
675         p = free_particles;
676         free_particles = p->next;
677         p->next = active_particles;
678         active_particles = p;
679         if (type == 0) // sparks
680         {
681                 p->texnum = smokeparticletexture[rand()&7];
682                 p->scale = 15;
683                 p->alpha = 64;
684                 p->color = (rand()&3)+12;
685                 p->type = pt_bulletpuff;
686                 p->die = cl.time + 1;
687                 VectorCopy(org, p->org);
688                 p->vel[0] = p->vel[1] = p->vel[2] = 0;
689         }
690         else // blood
691         {
692                 p->texnum = smokeparticletexture[rand()&7];
693                 p->scale = 12;
694                 p->alpha = 128;
695                 p->color = (rand()&3)+68;
696                 p->type = pt_bloodcloud;
697                 p->die = cl.time + 0.5;
698                 VectorCopy(org, p->org);
699                 p->vel[0] = p->vel[1] = p->vel[2] = 0;
700                 return;
701         }
702         for (i=0 ; i<count ; i++)
703         {
704                 if (!free_particles)
705                         return;
706                 p = free_particles;
707                 free_particles = p->next;
708                 p->next = active_particles;
709                 active_particles = p;
710
711                 p->texnum = flareparticletexture;
712                 p->scale = 2;
713                 p->alpha = 255;
714                 p->die = cl.time + 0.0625 * (rand()&15);
715                 /*
716                 if (type == 0) // sparks
717                 {
718                 */
719                         p->type = pt_dust;
720                         p->ramp = (rand()&3);
721                         p->color = ramp1[(int)p->ramp];
722                         for (j=0 ; j<3 ; j++)
723                         {
724                                 p->org[j] = org[j] + ((rand()&7)-4);
725                                 p->vel[j] = dir[j] + (rand()%192)-96;
726                         }
727                 /*
728                 }
729                 else // blood
730                 {
731                         p->type = pt_fadespark2;
732                         p->color = 67 + (rand()&3);
733                         for (j=0 ; j<3 ; j++)
734                         {
735                                 p->org[j] = org[j] + (rand()&7)-4;
736                                 p->vel[j] = dir[j] + (rand()&63)-32;
737                         }
738                 }
739                 */
740         }
741 }
742
743 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count)
744 {
745         int                     i, j;
746         particle_t      *p;
747         vec3_t          diff;
748         vec3_t          center;
749         vec3_t          velscale;
750         if (!r_particles.value) return; // LordHavoc: particles are optional
751
752         VectorSubtract(maxs, mins, diff);
753         center[0] = (mins[0] + maxs[0]) * 0.5;
754         center[1] = (mins[1] + maxs[1]) * 0.5;
755         center[2] = (mins[2] + maxs[2]) * 0.5;
756         velscale[0] = velspeed * 2.0 / diff[0];
757         velscale[1] = velspeed * 2.0 / diff[1];
758         velscale[2] = velspeed * 2.0 / diff[2];
759         
760         for (i=0 ; i<count ; i++)
761         {
762                 if (!free_particles)
763                         return;
764                 p = free_particles;
765                 free_particles = p->next;
766                 p->next = active_particles;
767                 active_particles = p;
768
769                 p->texnum = bloodcloudparticletexture;
770                 p->scale = 12;
771                 p->alpha = 96 + (rand()&63);
772                 p->die = cl.time + 2; //0.015625 * (rand()%128);
773                 p->type = pt_fadespark;
774                 p->color = (rand()&3)+68;
775 //              p->color = 67 + (rand()&3);
776                 for (j=0 ; j<3 ; j++)
777                 {
778                         p->org[j] = diff[j] * (float) (rand()%1024) * (1.0 / 1024.0) + mins[j];
779                         p->vel[j] = (p->org[j] - center[j]) * velscale[j];
780                 }
781         }
782 }
783
784 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel)
785 {
786         int                     i, j;
787         particle_t      *p;
788         vec3_t          diff;
789         float           t;
790         if (!r_particles.value) return; // LordHavoc: particles are optional
791         if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
792         if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
793         if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
794
795         VectorSubtract(maxs, mins, diff);
796         
797         for (i=0 ; i<count ; i++)
798         {
799                 if (!free_particles)
800                         return;
801                 p = free_particles;
802                 free_particles = p->next;
803                 p->next = active_particles;
804                 active_particles = p;
805
806                 p->texnum = flareparticletexture;
807                 p->scale = 6;
808                 p->alpha = 255;
809                 p->die = cl.time + 1 + (rand()&15)*0.0625;
810                 if (gravity)
811                         p->type = pt_grav;
812                 else
813                         p->type = pt_static;
814                 p->color = colorbase + (rand()&3);
815                 for (j=0 ; j<3 ; j++)
816                 {
817                         p->org[j] = diff[j] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[j];
818                         if (randomvel)
819                                 p->vel[j] = dir[j] + (rand()%randomvel)-(randomvel*0.5);
820                         else
821                                 p->vel[j] = 0;
822                 }
823         }
824 }
825
826 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type)
827 {
828         int                     i;
829         particle_t      *p;
830         vec3_t          diff;
831         vec3_t          org;
832         vec3_t          vel;
833         float           t, z;
834         if (!r_particles.value) return; // LordHavoc: particles are optional
835         if (maxs[0] <= mins[0]) {t = mins[0];mins[0] = maxs[0];maxs[0] = t;}
836         if (maxs[1] <= mins[1]) {t = mins[1];mins[1] = maxs[1];maxs[1] = t;}
837         if (maxs[2] <= mins[2]) {t = mins[2];mins[2] = maxs[2];maxs[2] = t;}
838         if (dir[2] < 0) // falling
839         {
840                 t = (maxs[2] - mins[2]) / -dir[2];
841                 z = maxs[2];
842         }
843         else // rising??
844         {
845                 t = (maxs[2] - mins[2]) / dir[2];
846                 z = mins[2];
847         }
848         if (t < 0 || t > 2) // sanity check
849                 t = 2;
850         t += cl.time;
851
852         VectorSubtract(maxs, mins, diff);
853         
854         for (i=0 ; i<count ; i++)
855         {
856                 if (!free_particles)
857                         return;
858                 p = free_particles;
859                 free_particles = p->next;
860                 p->next = active_particles;
861                 active_particles = p;
862
863                 vel[0] = dir[0] + (rand()&31) - 16;
864                 vel[1] = dir[1] + (rand()&31) - 16;
865                 vel[2] = dir[2] + (rand()&63) - 32;
866                 org[0] = diff[0] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[0];
867                 org[1] = diff[1] * (float) (rand()&1023) * (1.0 / 1024.0) + mins[1];
868                 org[2] = z;
869
870                 p->scale = 1.5;
871                 p->alpha = 255;
872                 p->die = t;
873                 if (type == 1)
874                 {
875                         p->texnum = particletexture;
876                         p->type = pt_snow;
877                 }
878                 else // 0
879                 {
880                         p->texnum = rainparticletexture;
881                         p->type = pt_static;
882                 }
883                 p->color = colorbase + (rand()&3);
884                 VectorCopy(org, p->org);
885                 VectorCopy(vel, p->vel);
886                 VectorCopy(vel, p->vel2);
887         }
888 }
889
890
891 /*
892 ===============
893 R_LavaSplash
894
895 ===============
896 */
897 void R_LavaSplash (vec3_t org)
898 {
899         int                     i, j, k;
900         particle_t      *p;
901         float           vel;
902         vec3_t          dir;
903         if (!r_particles.value) return; // LordHavoc: particles are optional
904
905         for (i=-16 ; i<16 ; i+=2)
906                 for (j=-16 ; j<16 ; j+=2)
907                         for (k=0 ; k<1 ; k++)
908                         {
909                                 if (!free_particles)
910                                         return;
911                                 p = free_particles;
912                                 free_particles = p->next;
913                                 p->next = active_particles;
914                                 active_particles = p;
915                 
916                                 p->texnum = flareparticletexture;
917                                 p->scale = 10;
918                                 p->alpha = 128;
919                                 p->die = cl.time + 2 + (rand()&31) * 0.02;
920                                 p->color = 224 + (rand()&7);
921                                 p->type = pt_slowgrav;
922                                 
923                                 dir[0] = j*8 + (rand()&7);
924                                 dir[1] = i*8 + (rand()&7);
925                                 dir[2] = 256;
926         
927                                 p->org[0] = org[0] + dir[0];
928                                 p->org[1] = org[1] + dir[1];
929                                 p->org[2] = org[2] + (rand()&63);
930         
931                                 VectorNormalize (dir);                                          
932                                 vel = 50 + (rand()&63);
933                                 VectorScale (dir, vel, p->vel);
934                         }
935 }
936
937 /*
938 ===============
939 R_TeleportSplash
940
941 ===============
942 */
943 void R_TeleportSplash (vec3_t org)
944 {
945         int                     i, j, k;
946         particle_t      *p;
947 //      vec3_t          dir;
948         if (!r_particles.value) return; // LordHavoc: particles are optional
949
950         /*
951         for (i=-16 ; i<16 ; i+=4)
952                 for (j=-16 ; j<16 ; j+=4)
953                         for (k=-24 ; k<32 ; k+=4)
954                         {
955                                 if (!free_particles)
956                                         return;
957                                 p = free_particles;
958                                 free_particles = p->next;
959                                 p->next = active_particles;
960                                 active_particles = p;
961                 
962                                 p->contents = 0;
963                                 p->texnum = particletexture;
964                                 p->scale = 2;
965                                 p->alpha = 255;
966                                 p->die = cl.time + 0.2 + (rand()&7) * 0.02;
967                                 p->color = 7 + (rand()&7);
968                                 p->type = pt_slowgrav;
969                                 
970                                 dir[0] = j*8;
971                                 dir[1] = i*8;
972                                 dir[2] = k*8;
973         
974                                 p->org[0] = org[0] + i + (rand()&3);
975                                 p->org[1] = org[1] + j + (rand()&3);
976                                 p->org[2] = org[2] + k + (rand()&3);
977         
978                                 VectorNormalize (dir);                                          
979                                 vel = 50 + (rand()&63);
980                                 VectorScale (dir, vel, p->vel);
981                         }
982         */
983
984         for (i=-24 ; i<24 ; i+=8)
985                 for (j=-24 ; j<24 ; j+=8)
986                         for (k=-24 ; k<32 ; k+=8)
987                         {
988                                 if (!free_particles)
989                                         return;
990                                 p = free_particles;
991                                 free_particles = p->next;
992                                 p->next = active_particles;
993                                 active_particles = p;
994                 
995                                 p->texnum = flareparticletexture;
996                                 p->scale = 4;
997                                 p->alpha = lhrandom(32,256);
998                                 p->die = cl.time + 5;
999                                 p->color = 254; //8 + (rand()&7);
1000                                 p->type = pt_fadespark;
1001                                 
1002                                 p->org[0] = org[0] + i + (rand()&7);
1003                                 p->org[1] = org[1] + j + (rand()&7);
1004                                 p->org[2] = org[2] + k + (rand()&7);
1005         
1006                                 p->vel[0] = i*2 + (rand()%25) - 12;
1007                                 p->vel[1] = j*2 + (rand()%25) - 12;
1008                                 p->vel[2] = k*2 + (rand()%25) - 12 + 40;
1009                         }
1010 }
1011
1012 void R_RocketTrail (vec3_t start, vec3_t end, int type, entity_t *ent)
1013 {
1014         vec3_t          vec;
1015         float           len, dec = 0, t, nt, speed;
1016         int                     j, contents, bubbles;
1017         particle_t      *p;
1018         static int      tracercount;
1019         if (!r_particles.value) return; // LordHavoc: particles are optional
1020
1021         t = cl.oldtime;
1022         nt = cl.time;
1023         if (ent->trail_leftover < 0)
1024                 ent->trail_leftover = 0;
1025         t += ent->trail_leftover;
1026         ent->trail_leftover -= (cl.time - cl.oldtime);
1027         if (t >= cl.time)
1028                 return;
1029
1030         contents = Mod_PointInLeaf(start, cl.worldmodel)->contents;
1031         if (contents == CONTENTS_SKY || contents == CONTENTS_LAVA)
1032                 return;
1033
1034         VectorSubtract (end, start, vec);
1035         len = VectorNormalizeLength (vec);
1036         if (len <= 0.01f)
1037                 return;
1038         speed = len / (nt - t);
1039
1040         bubbles = (contents == CONTENTS_WATER || contents == CONTENTS_SLIME);
1041
1042         while (t < nt)
1043         {
1044                 if (!free_particles)
1045                         return;
1046                 p = free_particles;
1047                 free_particles = p->next;
1048                 p->next = active_particles;
1049                 active_particles = p;
1050                 
1051                 p->vel[0] = p->vel[1] = p->vel[2] = 0;
1052                 p->die = cl.time + 2;
1053
1054                 switch (type)
1055                 {
1056                         case 0: // rocket trail
1057                         case 1: // grenade trail
1058                                 if (bubbles)
1059                                 {
1060                                         dec = 0.005f;
1061                                         p->texnum = bubbleparticletexture;
1062                                         p->scale = lhrandom(1,2);
1063                                         p->alpha = 255;
1064                                         p->color = (rand()&3)+12;
1065                                         p->type = pt_bubble;
1066                                         p->die = cl.time + 2;
1067                                         for (j=0 ; j<3 ; j++)
1068                                         {
1069                                                 p->vel[j] = (rand()&31)-16;
1070                                                 p->org[j] = start[j] + ((rand()&3)-2);
1071                                         }
1072                                 }
1073                                 else
1074                                 {
1075                                         dec = 0.02f;
1076                                         p->texnum = smokeparticletexture[rand()&7];
1077                                         p->scale = lhrandom(6, 10);
1078                                         p->alpha = 64 + (rand()&31);
1079                                         p->color = (rand()&3)+12;
1080                                         p->type = pt_smoke;
1081                                         p->die = cl.time + 10000;
1082                                         VectorCopy(start, p->org);
1083                                 }
1084                                 break;
1085
1086                                 /*
1087                         case 1: // smoke smoke
1088                                 dec = 0.016f;
1089                                 p->texnum = smokeparticletexture;
1090                                 p->scale = lhrandom(6,9);
1091                                 p->alpha = 64;
1092                                 if (r_smokecolor.value)
1093                                         p->color = r_smokecolor.value;
1094                                 else
1095                                         p->color = (rand()&3)+12;
1096                                 p->type = pt_smoke;
1097                                 p->die = cl.time + 1;
1098                                 VectorCopy(start, p->org);
1099                                 break;
1100                                 */
1101
1102                         case 2: // blood
1103                                 dec = 0.025f;
1104                                 p->texnum = smokeparticletexture[rand()&7];
1105                                 p->scale = lhrandom(6, 8);
1106                                 p->alpha = 255;
1107                                 p->color = (rand()&3)+68;
1108                                 p->type = pt_bloodcloud;
1109                                 p->die = cl.time + 2;
1110                                 for (j=0 ; j<3 ; j++)
1111                                 {
1112                                         p->vel[j] = (rand()&15)-8;
1113                                         p->org[j] = start[j] + ((rand()&3)-2);
1114                                 }
1115                                 break;
1116
1117                         case 3:
1118                         case 5: // tracer
1119                                 dec = 0.01f;
1120                                 p->texnum = flareparticletexture;
1121                                 p->scale = 2;
1122                                 p->alpha = 255;
1123                                 p->die = cl.time + 0.2; //5;
1124                                 p->type = pt_static;
1125                                 if (type == 3)
1126                                         p->color = 52 + ((tracercount&4)<<1);
1127                                 else
1128                                         p->color = 230 + ((tracercount&4)<<1);
1129
1130                                 tracercount++;
1131
1132                                 VectorCopy (start, p->org);
1133                                 if (tracercount & 1)
1134                                 {
1135                                         p->vel[0] = 30*vec[1];
1136                                         p->vel[1] = 30*-vec[0];
1137                                 }
1138                                 else
1139                                 {
1140                                         p->vel[0] = 30*-vec[1];
1141                                         p->vel[1] = 30*vec[0];
1142                                 }
1143                                 break;
1144
1145                         case 4: // slight blood
1146                                 dec = 0.025f; // sparse trail
1147                                 p->texnum = smokeparticletexture[rand()&7];
1148                                 p->scale = lhrandom(6, 8);
1149                                 p->alpha = 192;
1150                                 p->color = (rand()&3)+68;
1151                                 p->type = pt_fadespark2;
1152                                 p->die = cl.time + 2;
1153                                 for (j=0 ; j<3 ; j++)
1154                                 {
1155                                         p->vel[j] = (rand()&15)-8;
1156                                         p->org[j] = start[j] + ((rand()&3)-2);
1157                                 }
1158                                 break;
1159
1160                         case 6: // voor trail
1161                                 dec = 0.05f; // sparse trail
1162                                 p->texnum = smokeparticletexture[rand()&7];
1163                                 p->scale = lhrandom(3, 5);
1164                                 p->alpha = 255;
1165                                 p->color = 9*16 + 8 + (rand()&3);
1166                                 p->type = pt_fadespark2;
1167                                 p->die = cl.time + 2;
1168                                 for (j=0 ; j<3 ; j++)
1169                                 {
1170                                         p->vel[j] = (rand()&15)-8;
1171                                         p->org[j] = start[j] + ((rand()&3)-2);
1172                                 }
1173                                 break;
1174
1175                         case 7: // Nehahra smoke tracer
1176                                 dec = 0.14f;
1177                                 p->texnum = smokeparticletexture[rand()&7];
1178                                 p->scale = lhrandom(8, 12);
1179                                 p->alpha = 64;
1180                                 p->color = (rand()&3)+12;
1181                                 p->type = pt_smoke;
1182                                 p->die = cl.time + 10000;
1183                                 for (j=0 ; j<3 ; j++)
1184                                         p->org[j] = start[j] + ((rand()&3)-2);
1185                                 break;
1186                 }
1187                 
1188                 t += dec;
1189                 dec *= speed;
1190                 VectorMA (start, dec, vec, start);
1191         }
1192         ent->trail_leftover = t - cl.time;
1193 }
1194
1195 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent)
1196 {
1197         vec3_t          vec;
1198         float           len;
1199         particle_t      *p;
1200         if (!r_particles.value) return; // LordHavoc: particles are optional
1201
1202         VectorSubtract (end, start, vec);
1203         len = VectorNormalizeLength (vec);
1204         while (len > 0)
1205         {
1206                 len -= 3;
1207
1208                 if (!free_particles)
1209                         return;
1210                 p = free_particles;
1211                 free_particles = p->next;
1212                 p->next = active_particles;
1213                 active_particles = p;
1214                 
1215                 VectorCopy (vec3_origin, p->vel);
1216
1217                 p->texnum = flareparticletexture;
1218                 p->scale = 8;
1219                 p->alpha = 192;
1220                 p->color = color;
1221                 p->type = pt_smoke;
1222                 p->die = cl.time + 1;
1223                 VectorCopy(start, p->org);
1224 //              for (j=0 ; j<3 ; j++)
1225 //                      p->org[j] = start[j] + ((rand()&15)-8);
1226
1227                 VectorAdd (start, vec, start);
1228         }
1229 }
1230
1231
1232 extern qboolean lighthalf;
1233
1234 /*
1235 ===============
1236 R_DrawParticles
1237 ===============
1238 */
1239 extern  cvar_t  sv_gravity;
1240
1241 void R_DrawParticles (void)
1242 {
1243         particle_t              *p, *kill;
1244         int                             i, r,g,b,a;
1245         float                   grav, grav1, time1, time2, time3, dvel, frametime, scale, scale2;
1246         byte                    *color24;
1247         vec3_t                  up, right, uprightangles, forward2, up2, right2, v;
1248
1249         // LordHavoc: early out condition
1250         if (!active_particles)
1251                 return;
1252
1253         VectorScale (vup, 1.5, up);
1254         VectorScale (vright, 1.5, right);
1255
1256         uprightangles[0] = 0;
1257         uprightangles[1] = r_refdef.viewangles[1];
1258         uprightangles[2] = 0;
1259         AngleVectors (uprightangles, forward2, right2, up2);
1260
1261         frametime = cl.time - cl.oldtime;
1262         time3 = frametime * 15;
1263         time2 = frametime * 10; // 15;
1264         time1 = frametime * 5;
1265         grav = (grav1 = frametime * sv_gravity.value) * 0.05;
1266         dvel = 1+4*frametime;
1267
1268         for ( ;; ) 
1269         {
1270                 kill = active_particles;
1271                 if (kill && kill->die < cl.time)
1272                 {
1273                         active_particles = kill->next;
1274                         kill->next = free_particles;
1275                         free_particles = kill;
1276                         continue;
1277                 }
1278                 break;
1279         }
1280
1281         for (p=active_particles ; p ; p=p->next)
1282         {
1283                 for ( ;; )
1284                 {
1285                         kill = p->next;
1286                         if (kill && kill->die < cl.time)
1287                         {
1288                                 p->next = kill->next;
1289                                 kill->next = free_particles;
1290                                 free_particles = kill;
1291                                 continue;
1292                         }
1293                         break;
1294                 }
1295                 // LordHavoc: 'removed last in list' condition
1296                 if (!p)
1297                         break;
1298
1299                 VectorSubtract(p->org, r_refdef.vieworg, v);
1300                 if (DotProduct(v, v) >= 256.0f)
1301                 {
1302                         scale = p->scale * -0.5;scale2 = p->scale * 0.5;
1303                         color24 = (byte *) &d_8to24table[(int)p->color];
1304                         r = color24[0];
1305                         g = color24[1];
1306                         b = color24[2];
1307                         a = p->alpha;
1308                         if (lighthalf)
1309                         {
1310                                 r >>= 1;
1311                                 g >>= 1;
1312                                 b >>= 1;
1313                         }
1314                         transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA);
1315                         if (p->texnum == rainparticletexture) // rain streak
1316                         {
1317                                 transpolyvert(p->org[0] + up2[0]*scale  + right2[0]*scale , p->org[1] + up2[1]*scale  + right2[1]*scale , p->org[2] + up2[2]*scale  + right2[2]*scale , 0,1,r,g,b,a);
1318                                 transpolyvert(p->org[0] + up2[0]*scale2 + right2[0]*scale , p->org[1] + up2[1]*scale2 + right2[1]*scale , p->org[2] + up2[2]*scale2 + right2[2]*scale , 0,0,r,g,b,a);
1319                                 transpolyvert(p->org[0] + up2[0]*scale2 + right2[0]*scale2, p->org[1] + up2[1]*scale2 + right2[1]*scale2, p->org[2] + up2[2]*scale2 + right2[2]*scale2, 1,0,r,g,b,a);
1320                                 transpolyvert(p->org[0] + up2[0]*scale  + right2[0]*scale2, p->org[1] + up2[1]*scale  + right2[1]*scale2, p->org[2] + up2[2]*scale  + right2[2]*scale2, 1,1,r,g,b,a);
1321                         }
1322                         else
1323                         {
1324                                 transpolyvert(p->org[0] + up[0]*scale  + right[0]*scale , p->org[1] + up[1]*scale  + right[1]*scale , p->org[2] + up[2]*scale  + right[2]*scale , 0,1,r,g,b,a);
1325                                 transpolyvert(p->org[0] + up[0]*scale2 + right[0]*scale , p->org[1] + up[1]*scale2 + right[1]*scale , p->org[2] + up[2]*scale2 + right[2]*scale , 0,0,r,g,b,a);
1326                                 transpolyvert(p->org[0] + up[0]*scale2 + right[0]*scale2, p->org[1] + up[1]*scale2 + right[1]*scale2, p->org[2] + up[2]*scale2 + right[2]*scale2, 1,0,r,g,b,a);
1327                                 transpolyvert(p->org[0] + up[0]*scale  + right[0]*scale2, p->org[1] + up[1]*scale  + right[1]*scale2, p->org[2] + up[2]*scale  + right[2]*scale2, 1,1,r,g,b,a);
1328                         }
1329                         transpolyend();
1330                 }
1331
1332                 p->org[0] += p->vel[0]*frametime;
1333                 p->org[1] += p->vel[1]*frametime;
1334                 p->org[2] += p->vel[2]*frametime;
1335                 
1336                 switch (p->type)
1337                 {
1338                 case pt_static:
1339                         break;
1340                 case pt_fire:
1341                         p->ramp += time1;
1342                         if (p->ramp >= 6)
1343                                 p->die = -1;
1344                         else
1345                                 p->color = ramp3[(int)p->ramp];
1346                         p->vel[2] += grav;
1347                         break;
1348
1349                 case pt_explode:
1350                         p->ramp += time2;
1351                         if (p->ramp >=8)
1352                                 p->die = -1;
1353                         else
1354                                 p->color = ramp1[(int)p->ramp];
1355 //                      p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1356                         for (i=0 ; i<3 ; i++)
1357                                 p->vel[i] *= dvel;
1358 //                      p->vel[2] -= grav;
1359                         break;
1360
1361                 case pt_explode2:
1362                         p->ramp += time3;
1363                         if (p->ramp >= 8)
1364                                 p->die = -1;
1365                         else
1366                                 p->color = ramp2[(int)p->ramp];
1367 //                      p->vel[2] -= grav1; // LordHavoc: apply full gravity to explosion sparks
1368                         for (i=0 ; i<3 ; i++)
1369 //                              p->vel[i] -= p->vel[i]*frametime;
1370                                 p->vel[i] *= dvel;
1371 ////                    p->vel[2] -= grav;
1372                         break;
1373
1374                 case pt_blob:
1375                         for (i=0 ; i<3 ; i++)
1376                                 p->vel[i] += p->vel[i]*dvel;
1377                         p->vel[2] -= grav;
1378                         break;
1379
1380                 case pt_blob2:
1381                         for (i=0 ; i<2 ; i++)
1382                                 p->vel[i] -= p->vel[i]*dvel;
1383                         p->vel[2] -= grav;
1384                         break;
1385
1386                 case pt_grav:
1387                         p->vel[2] -= grav1;
1388                         break;
1389                 case pt_slowgrav:
1390                         p->vel[2] -= grav;
1391                         break;
1392 // LordHavoc: gunshot spark showers
1393                 case pt_dust:
1394                         p->ramp += time1;
1395                         p->scale -= frametime * 4;
1396                         if (p->ramp >= 8 || p->scale <= 0)
1397                                 p->die = -1;
1398                         else
1399                                 p->color = ramp3[(int)p->ramp];
1400                         p->vel[2] -= grav1;
1401                         break;
1402 // LordHavoc: for smoke trails
1403                 case pt_smoke:
1404                         p->scale += frametime * 4;
1405                         p->alpha -= frametime * 48;
1406 //                      p->vel[2] += grav;
1407                         if (p->alpha < 1)
1408                                 p->die = -1;
1409                         break;
1410                 case pt_snow:
1411                         if (cl.time > p->time2)
1412                         {
1413                                 p->time2 = cl.time + (rand() & 3) * 0.1;
1414                                 p->vel[0] = (rand()&63)-32 + p->vel2[0];
1415                                 p->vel[1] = (rand()&63)-32 + p->vel2[1];
1416                                 p->vel[2] = (rand()&63)-32 + p->vel2[2];
1417                         }
1418                         break;
1419                 case pt_bulletpuff:
1420                         p->scale -= frametime * 64;
1421                         p->alpha -= frametime * 1024;
1422                         p->vel[2] -= grav;
1423                         if (p->alpha < 1 || p->scale < 1)
1424                                 p->die = -1;
1425                         break;
1426                 case pt_bloodcloud:
1427                         p->scale += frametime * 4;
1428                         p->alpha -= frametime * 64;
1429                         p->vel[2] -= grav;
1430                         if (p->alpha < 1 || p->scale < 1)
1431                                 p->die = -1;
1432                         break;
1433                 case pt_fadespark:
1434                         p->alpha -= frametime * 256;
1435                         p->vel[2] -= grav;
1436                         if (p->alpha < 1)
1437                                 p->die = -1;
1438                         break;
1439                 case pt_fadespark2:
1440                         p->alpha -= frametime * 512;
1441                         p->vel[2] -= grav;
1442                         if (p->alpha < 1)
1443                                 p->die = -1;
1444                         break;
1445                 case pt_fallfadespark:
1446                         p->alpha -= frametime * 256;
1447                         p->vel[2] -= grav1;
1448                         if (p->alpha < 1)
1449                                 p->die = -1;
1450                         break;
1451                 case pt_fallfadespark2:
1452                         p->alpha -= frametime * 512;
1453                         p->vel[2] -= grav1;
1454                         if (p->alpha < 1)
1455                                 p->die = -1;
1456                         break;
1457                 case pt_fade:
1458                         p->alpha -= frametime * 512;
1459                         if (p->alpha < 1)
1460                                 p->die = -1;
1461                         break;
1462                 case pt_bubble:
1463                         if (Mod_PointInLeaf(p->org, cl.worldmodel)->contents == CONTENTS_EMPTY)
1464                                 p->die = -1;
1465                         p->vel[2] += grav1 * 2;
1466                         if (p->vel[2] >= 200)
1467                                 p->vel[2] = lhrandom(130, 200);
1468                         if (cl.time > p->time2)
1469                         {
1470                                 p->time2 = cl.time + lhrandom(0, 0.5);
1471                                 p->vel[0] = lhrandom(-32,32);
1472                                 p->vel[1] = lhrandom(-32,32);
1473                         }
1474                         p->alpha -= frametime * 64;
1475                         if (p->alpha < 1)
1476                                 p->die = -1;
1477                         break;
1478                 }
1479         }
1480 }
1481