1487 lines
26 KiB
C
1487 lines
26 KiB
C
/*
|
|
Copyright (C) 1997-2001 Id Software, Inc.
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
// cl_fx.c -- entity effects parsing and management
|
|
|
|
#include "client.h"
|
|
|
|
void CL_LogoutEffect (vec3_t org, int type);
|
|
void CL_ItemRespawnParticles (vec3_t org);
|
|
|
|
extern model_t *cl_mod_smoke;
|
|
extern model_t *cl_mod_flash;
|
|
|
|
/*
|
|
==============================================================
|
|
|
|
LIGHT STYLE MANAGEMENT
|
|
|
|
==============================================================
|
|
*/
|
|
|
|
typedef struct
|
|
{
|
|
int length;
|
|
float value[3];
|
|
float map[MAX_QPATH];
|
|
} clightstyle_t;
|
|
|
|
clightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
|
|
int lastofs;
|
|
|
|
/*
|
|
================
|
|
CL_ClearLightStyles
|
|
================
|
|
*/
|
|
void CL_ClearLightStyles (void)
|
|
{
|
|
memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
|
|
lastofs = -1;
|
|
}
|
|
|
|
/*
|
|
================
|
|
CL_RunLightStyles
|
|
================
|
|
*/
|
|
void CL_RunLightStyles (void)
|
|
{
|
|
int ofs;
|
|
int i;
|
|
clightstyle_t *ls;
|
|
|
|
ofs = cl.time / 100;
|
|
if (ofs == lastofs)
|
|
return;
|
|
lastofs = ofs;
|
|
|
|
for (i=0,ls=cl_lightstyle ; i<MAX_LIGHTSTYLES ; i++, ls++)
|
|
{
|
|
if (!ls->length)
|
|
{
|
|
ls->value[0] = ls->value[1] = ls->value[2] = 1.0;
|
|
continue;
|
|
}
|
|
if (ls->length == 1)
|
|
ls->value[0] = ls->value[1] = ls->value[2] = ls->map[0];
|
|
else
|
|
ls->value[0] = ls->value[1] = ls->value[2] = ls->map[ofs%ls->length];
|
|
}
|
|
}
|
|
|
|
|
|
void CL_SetLightstyle (int i)
|
|
{
|
|
char *s;
|
|
int j, k;
|
|
|
|
s = cl.configstrings[i+CS_LIGHTS];
|
|
|
|
j = strlen (s);
|
|
if (j >= MAX_QPATH)
|
|
Host_Error("CL_SetLightStyle: lightstyle %s is too long\n", s );
|
|
|
|
cl_lightstyle[i].length = j;
|
|
|
|
for (k=0 ; k<j ; k++)
|
|
cl_lightstyle[i].map[k] = (float)(s[k]-'a')/(float)('m'-'a');
|
|
}
|
|
|
|
/*
|
|
================
|
|
CL_AddLightStyles
|
|
================
|
|
*/
|
|
void CL_AddLightStyles (void)
|
|
{
|
|
int i;
|
|
clightstyle_t *ls;
|
|
|
|
for (i=0,ls=cl_lightstyle ; i<MAX_LIGHTSTYLES ; i++, ls++)
|
|
V_AddLightStyle (i, ls->value[0], ls->value[1], ls->value[2]);
|
|
}
|
|
|
|
/*
|
|
==============================================================
|
|
|
|
DLIGHT MANAGEMENT
|
|
|
|
==============================================================
|
|
*/
|
|
|
|
cdlight_t cl_dlights[MAX_DLIGHTS];
|
|
|
|
/*
|
|
================
|
|
CL_ClearDlights
|
|
================
|
|
*/
|
|
void CL_ClearDlights (void)
|
|
{
|
|
memset (cl_dlights, 0, sizeof(cl_dlights));
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_AllocDlight
|
|
|
|
===============
|
|
*/
|
|
cdlight_t *CL_AllocDlight (int key)
|
|
{
|
|
int i;
|
|
cdlight_t *dl;
|
|
|
|
// first look for an exact key match
|
|
if (key)
|
|
{
|
|
dl = cl_dlights;
|
|
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
|
|
{
|
|
if (dl->key == key)
|
|
{
|
|
memset (dl, 0, sizeof(*dl));
|
|
dl->key = key;
|
|
return dl;
|
|
}
|
|
}
|
|
}
|
|
|
|
// then look for anything else
|
|
dl = cl_dlights;
|
|
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
|
|
{
|
|
if (dl->die < cl.time)
|
|
{
|
|
memset (dl, 0, sizeof(*dl));
|
|
dl->key = key;
|
|
return dl;
|
|
}
|
|
}
|
|
|
|
dl = &cl_dlights[0];
|
|
memset (dl, 0, sizeof(*dl));
|
|
dl->key = key;
|
|
return dl;
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_NewDlight
|
|
===============
|
|
*/
|
|
void CL_NewDlight (int key, float x, float y, float z, float radius, float time)
|
|
{
|
|
cdlight_t *dl;
|
|
|
|
dl = CL_AllocDlight (key);
|
|
dl->origin[0] = x;
|
|
dl->origin[1] = y;
|
|
dl->origin[2] = z;
|
|
dl->radius = radius;
|
|
dl->die = cl.time + time;
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_RunDLights
|
|
|
|
===============
|
|
*/
|
|
void CL_RunDLights (void)
|
|
{
|
|
int i;
|
|
cdlight_t *dl;
|
|
|
|
dl = cl_dlights;
|
|
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
|
|
{
|
|
if (!dl->radius)
|
|
continue;
|
|
|
|
if (dl->die < cl.time)
|
|
{
|
|
dl->radius = 0;
|
|
return;
|
|
}
|
|
dl->radius -= cls.frametime*dl->decay;
|
|
if (dl->radius < 0)
|
|
dl->radius = 0;
|
|
}
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_AddDLights
|
|
|
|
===============
|
|
*/
|
|
void CL_AddDLights (void)
|
|
{
|
|
int i;
|
|
cdlight_t *dl;
|
|
|
|
dl = cl_dlights;
|
|
|
|
for (i = 0; i < MAX_DLIGHTS; i++, dl++)
|
|
{
|
|
if (!dl->radius) continue;
|
|
V_AddLight (dl->origin, dl->radius, dl->color[0], dl->color[1], dl->color[2]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
==============================================================
|
|
|
|
PARTICLE MANAGEMENT
|
|
|
|
==============================================================
|
|
*/
|
|
|
|
/*
|
|
// THIS HAS BEEN RELOCATED TO CLIENT.H
|
|
typedef struct cparticle_s
|
|
{
|
|
struct cparticle_s *next;
|
|
|
|
float time;
|
|
|
|
vec3_t org;
|
|
vec3_t vel;
|
|
vec3_t accel;
|
|
float color;
|
|
float colorvel;
|
|
float alpha;
|
|
float alphavel;
|
|
} cparticle_t;
|
|
|
|
|
|
#define PARTICLE_GRAVITY 40
|
|
*/
|
|
|
|
cparticle_t *active_particles, *free_particles;
|
|
|
|
cparticle_t particles[MAX_PARTICLES];
|
|
int cl_numparticles = MAX_PARTICLES;
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_ClearParticles
|
|
===============
|
|
*/
|
|
void CL_ClearParticles (void)
|
|
{
|
|
int i;
|
|
|
|
free_particles = &particles[0];
|
|
active_particles = NULL;
|
|
|
|
for (i=0 ;i<cl_numparticles ; i++)
|
|
particles[i].next = &particles[i+1];
|
|
particles[cl_numparticles-1].next = NULL;
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_ParticleEffect
|
|
|
|
Wall impact puffs
|
|
===============
|
|
*/
|
|
void CL_ParticleEffect (vec3_t org, vec3_t dir, int color, int count)
|
|
{
|
|
int i, j;
|
|
cparticle_t *p;
|
|
float d;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = color + (rand()&7);
|
|
|
|
d = rand()&31;
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
|
|
p->vel[j] = crand()*20;
|
|
}
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -1.0 / (0.5 + frand()*0.3);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_ParticleEffect2
|
|
===============
|
|
*/
|
|
void CL_ParticleEffect2 (vec3_t org, vec3_t dir, int color, int count)
|
|
{
|
|
int i, j;
|
|
cparticle_t *p;
|
|
float d;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = color;
|
|
|
|
d = rand()&7;
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
|
|
p->vel[j] = crand()*20;
|
|
}
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -1.0 / (0.5 + frand()*0.3);
|
|
}
|
|
}
|
|
|
|
|
|
// RAFAEL
|
|
/*
|
|
===============
|
|
CL_ParticleEffect3
|
|
===============
|
|
*/
|
|
void CL_ParticleEffect3 (vec3_t org, vec3_t dir, int color, int count)
|
|
{
|
|
int i, j;
|
|
cparticle_t *p;
|
|
float d;
|
|
|
|
for (i=0 ; i<count ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = color;
|
|
|
|
d = rand()&7;
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
|
|
p->vel[j] = crand()*20;
|
|
}
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = PARTICLE_GRAVITY;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -1.0 / (0.5 + frand()*0.3);
|
|
}
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_TeleporterParticles
|
|
===============
|
|
*/
|
|
void CL_TeleporterParticles (entity_state_t *ent)
|
|
{
|
|
int i, j;
|
|
cparticle_t *p;
|
|
|
|
for (i=0 ; i<8 ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = 0xdb;
|
|
|
|
for (j=0 ; j<2 ; j++)
|
|
{
|
|
p->org[j] = ent->origin[j] - 16 + (rand()&31);
|
|
p->vel[j] = crand()*14;
|
|
}
|
|
|
|
p->org[2] = ent->origin[2] - 8 + (rand()&7);
|
|
p->vel[2] = 80 + (rand()&7);
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -0.5;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_LogoutEffect
|
|
|
|
===============
|
|
*/
|
|
void CL_LogoutEffect (vec3_t org, int type)
|
|
{
|
|
int i, j;
|
|
cparticle_t *p;
|
|
|
|
for (i=0 ; i<500 ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = 0xe0 + (rand()&7); // yellow
|
|
p->org[0] = org[0] - 16 + frand()*32;
|
|
p->org[1] = org[1] - 16 + frand()*32;
|
|
p->org[2] = org[2] - 24 + frand()*56;
|
|
|
|
for (j=0 ; j<3 ; j++)
|
|
p->vel[j] = crand()*20;
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -1.0 / (1.0 + frand()*0.3);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_ItemRespawnParticles
|
|
|
|
===============
|
|
*/
|
|
void CL_ItemRespawnParticles (vec3_t org)
|
|
{
|
|
int i, j;
|
|
cparticle_t *p;
|
|
|
|
for (i=0 ; i<64 ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
|
|
p->color = 0xd4 + (rand()&3); // green
|
|
|
|
p->org[0] = org[0] + crand();
|
|
p->org[1] = org[1] + crand();
|
|
p->org[2] = org[2] + crand();
|
|
|
|
for (j=0 ; j<3 ; j++)
|
|
p->vel[j] = crand();
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY*0.2;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -1.0 / (1.0 + frand()*0.3);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_ExplosionParticles
|
|
===============
|
|
*/
|
|
void CL_ExplosionParticles (vec3_t org)
|
|
{
|
|
int i, j;
|
|
cparticle_t *p;
|
|
|
|
for (i=0 ; i<256 ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = 0xe0 + (rand()&7);
|
|
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = org[j] + ((rand()%32)-16);
|
|
p->vel[j] = (rand()%384)-192;
|
|
}
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -0.8 / (0.5 + frand()*0.3);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_BigTeleportParticles
|
|
===============
|
|
*/
|
|
void CL_BigTeleportParticles (vec3_t org)
|
|
{
|
|
int i;
|
|
cparticle_t *p;
|
|
float angle, dist;
|
|
static int colortable[4] = {2*8,13*8,21*8,18*8};
|
|
|
|
for (i=0 ; i<4096 ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
|
|
p->color = colortable[rand()&3];
|
|
|
|
angle = M_PI*2*(rand()&1023)/1023.0;
|
|
dist = rand()&31;
|
|
p->org[0] = org[0] + cos(angle)*dist;
|
|
p->vel[0] = cos(angle)*(70+(rand()&63));
|
|
p->accel[0] = -cos(angle)*100;
|
|
|
|
p->org[1] = org[1] + sin(angle)*dist;
|
|
p->vel[1] = sin(angle)*(70+(rand()&63));
|
|
p->accel[1] = -sin(angle)*100;
|
|
|
|
p->org[2] = org[2] + 8 + (rand()%90);
|
|
p->vel[2] = -100 + (rand()&31);
|
|
p->accel[2] = PARTICLE_GRAVITY*4;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -0.3 / (0.5 + frand()*0.3);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_BlasterParticles
|
|
|
|
Wall impact puffs
|
|
===============
|
|
*/
|
|
void CL_BlasterParticles (vec3_t org, vec3_t dir)
|
|
{
|
|
int i, j;
|
|
cparticle_t *p;
|
|
float d;
|
|
int count;
|
|
|
|
count = 40;
|
|
for (i=0 ; i<count ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = 0xe0 + (rand()&7);
|
|
|
|
d = rand()&15;
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = org[j] + ((rand()&7)-4) + d*dir[j];
|
|
p->vel[j] = dir[j] * 30 + crand()*40;
|
|
}
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -1.0 / (0.5 + frand()*0.3);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_BlasterTrail
|
|
|
|
===============
|
|
*/
|
|
void CL_BlasterTrail (vec3_t start, vec3_t end)
|
|
{
|
|
vec3_t move;
|
|
vec3_t vec;
|
|
float len;
|
|
int j;
|
|
cparticle_t *p;
|
|
int dec;
|
|
|
|
VectorCopy (start, move);
|
|
VectorSubtract (end, start, vec);
|
|
len = VectorNormalize (vec);
|
|
|
|
dec = 5;
|
|
VectorScale (vec, 5, vec);
|
|
|
|
// FIXME: this is a really silly way to have a loop
|
|
while (len > 0)
|
|
{
|
|
len -= dec;
|
|
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
VectorClear (p->accel);
|
|
|
|
p->time = cl.time;
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (0.3+frand()*0.2);
|
|
p->color = 0xe0;
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = move[j] + crand();
|
|
p->vel[j] = crand()*5;
|
|
p->accel[j] = 0;
|
|
}
|
|
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_QuadTrail
|
|
|
|
===============
|
|
*/
|
|
void CL_QuadTrail (vec3_t start, vec3_t end)
|
|
{
|
|
vec3_t move;
|
|
vec3_t vec;
|
|
float len;
|
|
int j;
|
|
cparticle_t *p;
|
|
int dec;
|
|
|
|
VectorCopy (start, move);
|
|
VectorSubtract (end, start, vec);
|
|
len = VectorNormalize (vec);
|
|
|
|
dec = 5;
|
|
VectorScale (vec, 5, vec);
|
|
|
|
while (len > 0)
|
|
{
|
|
len -= dec;
|
|
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
VectorClear (p->accel);
|
|
|
|
p->time = cl.time;
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (0.8+frand()*0.2);
|
|
p->color = 115;
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = move[j] + crand()*16;
|
|
p->vel[j] = crand()*5;
|
|
p->accel[j] = 0;
|
|
}
|
|
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_FlagTrail
|
|
|
|
===============
|
|
*/
|
|
void CL_FlagTrail (vec3_t start, vec3_t end, float color)
|
|
{
|
|
vec3_t move;
|
|
vec3_t vec;
|
|
float len;
|
|
int j;
|
|
cparticle_t *p;
|
|
int dec;
|
|
|
|
VectorCopy (start, move);
|
|
VectorSubtract (end, start, vec);
|
|
len = VectorNormalize (vec);
|
|
|
|
dec = 5;
|
|
VectorScale (vec, 5, vec);
|
|
|
|
while (len > 0)
|
|
{
|
|
len -= dec;
|
|
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
VectorClear (p->accel);
|
|
|
|
p->time = cl.time;
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (0.8+frand()*0.2);
|
|
p->color = color;
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = move[j] + crand()*16;
|
|
p->vel[j] = crand()*5;
|
|
p->accel[j] = 0;
|
|
}
|
|
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_DiminishingTrail
|
|
|
|
===============
|
|
*/
|
|
void CL_DiminishingTrail (vec3_t start, vec3_t end, centity_t *old)
|
|
{
|
|
vec3_t move;
|
|
vec3_t vec;
|
|
float len;
|
|
int j;
|
|
cparticle_t *p;
|
|
float dec;
|
|
float orgscale;
|
|
float velscale;
|
|
|
|
VectorCopy (start, move);
|
|
VectorSubtract (end, start, vec);
|
|
len = VectorNormalize (vec);
|
|
|
|
dec = 0.5;
|
|
VectorScale (vec, dec, vec);
|
|
|
|
if (old->trailcount > 900)
|
|
{
|
|
orgscale = 4;
|
|
velscale = 15;
|
|
}
|
|
else if (old->trailcount > 800)
|
|
{
|
|
orgscale = 2;
|
|
velscale = 10;
|
|
}
|
|
else
|
|
{
|
|
orgscale = 1;
|
|
velscale = 5;
|
|
}
|
|
|
|
while (len > 0)
|
|
{
|
|
len -= dec;
|
|
|
|
if (!free_particles)
|
|
return;
|
|
|
|
// drop less particles as it flies
|
|
if ((rand()&1023) < old->trailcount)
|
|
{
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
VectorClear (p->accel);
|
|
|
|
p->time = cl.time;
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (1+frand()*0.2);
|
|
p->color = 4 + (rand()&7);
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = move[j] + crand()*orgscale;
|
|
p->vel[j] = crand()*velscale;
|
|
}
|
|
p->accel[2] = 20;
|
|
}
|
|
|
|
old->trailcount -= 5;
|
|
if (old->trailcount < 100)
|
|
old->trailcount = 100;
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
}
|
|
|
|
void MakeNormalVectors (vec3_t forward, vec3_t right, vec3_t up)
|
|
{
|
|
float d;
|
|
|
|
// this rotate and negat guarantees a vector
|
|
// not colinear with the original
|
|
right[1] = -forward[0];
|
|
right[2] = forward[1];
|
|
right[0] = forward[2];
|
|
|
|
d = DotProduct (right, forward);
|
|
VectorMA (right, -d, forward, right);
|
|
VectorNormalize (right);
|
|
CrossProduct (right, forward, up);
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_RocketTrail
|
|
|
|
===============
|
|
*/
|
|
void CL_RocketTrail (vec3_t start, vec3_t end, centity_t *old)
|
|
{
|
|
vec3_t move;
|
|
vec3_t vec;
|
|
float len;
|
|
int j;
|
|
cparticle_t *p;
|
|
float dec;
|
|
|
|
// smoke
|
|
CL_DiminishingTrail (start, end, old);
|
|
|
|
// fire
|
|
VectorCopy (start, move);
|
|
VectorSubtract (end, start, vec);
|
|
len = VectorNormalize (vec);
|
|
|
|
dec = 1;
|
|
VectorScale (vec, dec, vec);
|
|
|
|
while (len > 0)
|
|
{
|
|
len -= dec;
|
|
|
|
if (!free_particles)
|
|
return;
|
|
|
|
if ( (rand()&7) == 0)
|
|
{
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
VectorClear (p->accel);
|
|
p->time = cl.time;
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (1+frand()*0.2);
|
|
p->color = 0xdc + (rand()&3);
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = move[j] + crand()*5;
|
|
p->vel[j] = crand()*20;
|
|
}
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
}
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_RailTrail
|
|
|
|
===============
|
|
*/
|
|
void CL_RailTrail (vec3_t start, vec3_t end)
|
|
{
|
|
vec3_t move;
|
|
vec3_t vec;
|
|
float len;
|
|
int j;
|
|
cparticle_t *p;
|
|
float dec;
|
|
vec3_t right, up;
|
|
int i;
|
|
float d, c, s;
|
|
vec3_t dir;
|
|
byte clr = 0x74;
|
|
|
|
VectorCopy (start, move);
|
|
VectorSubtract (end, start, vec);
|
|
len = VectorNormalize (vec);
|
|
|
|
MakeNormalVectors (vec, right, up);
|
|
|
|
for (i=0 ; i<len ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
VectorClear (p->accel);
|
|
|
|
d = i * 0.1;
|
|
c = cos(d);
|
|
s = sin(d);
|
|
|
|
VectorScale (right, c, dir);
|
|
VectorMA (dir, s, up, dir);
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (1+frand()*0.2);
|
|
p->color = clr + (rand()&7);
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = move[j] + dir[j]*3;
|
|
p->vel[j] = dir[j]*6;
|
|
}
|
|
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
|
|
dec = 0.75;
|
|
VectorScale (vec, dec, vec);
|
|
VectorCopy (start, move);
|
|
|
|
while (len > 0)
|
|
{
|
|
len -= dec;
|
|
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
VectorClear (p->accel);
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (0.6+frand()*0.2);
|
|
p->color = 0x0 + rand()&15;
|
|
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = move[j] + crand()*3;
|
|
p->vel[j] = crand()*3;
|
|
p->accel[j] = 0;
|
|
}
|
|
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
}
|
|
|
|
// RAFAEL
|
|
/*
|
|
===============
|
|
CL_IonripperTrail
|
|
===============
|
|
*/
|
|
void CL_IonripperTrail (vec3_t start, vec3_t ent)
|
|
{
|
|
vec3_t move;
|
|
vec3_t vec;
|
|
float len;
|
|
int j;
|
|
cparticle_t *p;
|
|
int dec;
|
|
int left = 0;
|
|
|
|
VectorCopy (start, move);
|
|
VectorSubtract (ent, start, vec);
|
|
len = VectorNormalize (vec);
|
|
|
|
dec = 5;
|
|
VectorScale (vec, 5, vec);
|
|
|
|
while (len > 0)
|
|
{
|
|
len -= dec;
|
|
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
VectorClear (p->accel);
|
|
|
|
p->time = cl.time;
|
|
p->alpha = 0.5;
|
|
p->alphavel = -1.0 / (0.3 + frand() * 0.2);
|
|
p->color = 0xe4 + (rand()&3);
|
|
|
|
for (j=0; j<3; j++)
|
|
{
|
|
p->org[j] = move[j];
|
|
p->accel[j] = 0;
|
|
}
|
|
if (left)
|
|
{
|
|
left = 0;
|
|
p->vel[0] = 10;
|
|
}
|
|
else
|
|
{
|
|
left = 1;
|
|
p->vel[0] = -10;
|
|
}
|
|
|
|
p->vel[1] = 0;
|
|
p->vel[2] = 0;
|
|
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_BubbleTrail
|
|
|
|
===============
|
|
*/
|
|
void CL_BubbleTrail (vec3_t start, vec3_t end)
|
|
{
|
|
vec3_t move;
|
|
vec3_t vec;
|
|
float len;
|
|
int i, j;
|
|
cparticle_t *p;
|
|
float dec;
|
|
|
|
VectorCopy (start, move);
|
|
VectorSubtract (end, start, vec);
|
|
len = VectorNormalize (vec);
|
|
|
|
dec = 32;
|
|
VectorScale (vec, dec, vec);
|
|
|
|
for (i=0 ; i<len ; i+=dec)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
VectorClear (p->accel);
|
|
p->time = cl.time;
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (1+frand()*0.2);
|
|
p->color = 4 + (rand()&7);
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = move[j] + crand()*2;
|
|
p->vel[j] = crand()*5;
|
|
}
|
|
p->vel[2] += 6;
|
|
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
}
|
|
|
|
/*
|
|
===============
|
|
CL_TrapParticles
|
|
===============
|
|
*/
|
|
// RAFAEL
|
|
void CL_TrapParticles (entity_t *ent)
|
|
{
|
|
vec3_t move;
|
|
vec3_t vec;
|
|
vec3_t start, end;
|
|
float len;
|
|
int j;
|
|
cparticle_t *p;
|
|
int dec;
|
|
|
|
ent->origin[2]-=14;
|
|
VectorCopy (ent->origin, start);
|
|
VectorCopy (ent->origin, end);
|
|
end[2]+=64;
|
|
|
|
VectorCopy (start, move);
|
|
VectorSubtract (end, start, vec);
|
|
len = VectorNormalize (vec);
|
|
|
|
dec = 5;
|
|
VectorScale (vec, 5, vec);
|
|
|
|
// FIXME: this is a really silly way to have a loop
|
|
while (len > 0)
|
|
{
|
|
len -= dec;
|
|
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
VectorClear (p->accel);
|
|
|
|
p->time = cl.time;
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (0.3+frand()*0.2);
|
|
p->color = 0xe0;
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = move[j] + crand();
|
|
p->vel[j] = crand()*15;
|
|
p->accel[j] = 0;
|
|
}
|
|
p->accel[2] = PARTICLE_GRAVITY;
|
|
|
|
VectorAdd (move, vec, move);
|
|
}
|
|
|
|
{
|
|
|
|
|
|
int i, j, k;
|
|
cparticle_t *p;
|
|
float vel;
|
|
vec3_t dir;
|
|
vec3_t org;
|
|
|
|
|
|
ent->origin[2]+=14;
|
|
VectorCopy (ent->origin, org);
|
|
|
|
|
|
for (i=-2 ; i<=2 ; i+=4)
|
|
for (j=-2 ; j<=2 ; j+=4)
|
|
for (k=-2 ; k<=4 ; k+=4)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = 0xe0 + (rand()&3);
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (0.3 + (rand()&7) * 0.02);
|
|
|
|
p->org[0] = org[0] + i + ((rand()&23) * crand());
|
|
p->org[1] = org[1] + j + ((rand()&23) * crand());
|
|
p->org[2] = org[2] + k + ((rand()&23) * crand());
|
|
|
|
dir[0] = j;
|
|
dir[1] = i;
|
|
dir[2] = k;
|
|
|
|
VectorNormalize (dir);
|
|
vel = 50 + rand()&63;
|
|
VectorScale (dir, vel, p->vel);
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_BFGExplosionParticles
|
|
===============
|
|
*/
|
|
//FIXME combined with CL_ExplosionParticles
|
|
void CL_BFGExplosionParticles (vec3_t org)
|
|
{
|
|
int i, j;
|
|
cparticle_t *p;
|
|
|
|
for (i=0 ; i<256 ; i++)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = 0xd0 + (rand()&7);
|
|
|
|
for (j=0 ; j<3 ; j++)
|
|
{
|
|
p->org[j] = org[j] + ((rand()%32)-16);
|
|
p->vel[j] = (rand()%384)-192;
|
|
}
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
p->alpha = 1.0;
|
|
|
|
p->alphavel = -0.8 / (0.5 + frand()*0.3);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_TeleportParticles
|
|
|
|
===============
|
|
*/
|
|
void CL_TeleportParticles (vec3_t org)
|
|
{
|
|
int i, j, k;
|
|
cparticle_t *p;
|
|
float vel;
|
|
vec3_t dir;
|
|
|
|
for (i=-16 ; i<=16 ; i+=4)
|
|
for (j=-16 ; j<=16 ; j+=4)
|
|
for (k=-16 ; k<=32 ; k+=4)
|
|
{
|
|
if (!free_particles)
|
|
return;
|
|
p = free_particles;
|
|
free_particles = p->next;
|
|
p->next = active_particles;
|
|
active_particles = p;
|
|
|
|
p->time = cl.time;
|
|
p->color = 7 + (rand()&7);
|
|
|
|
p->alpha = 1.0;
|
|
p->alphavel = -1.0 / (0.3 + (rand()&7) * 0.02);
|
|
|
|
p->org[0] = org[0] + i + (rand()&3);
|
|
p->org[1] = org[1] + j + (rand()&3);
|
|
p->org[2] = org[2] + k + (rand()&3);
|
|
|
|
dir[0] = j;
|
|
dir[1] = i;
|
|
dir[2] = k;
|
|
|
|
VectorNormalize (dir);
|
|
vel = 50 + (rand()&63);
|
|
VectorScale (dir, vel, p->vel);
|
|
|
|
p->accel[0] = p->accel[1] = 0;
|
|
p->accel[2] = -PARTICLE_GRAVITY;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
===============
|
|
CL_AddParticles
|
|
===============
|
|
*/
|
|
void CL_AddParticles (void)
|
|
{
|
|
cparticle_t *p, *next;
|
|
float alpha;
|
|
float time, time2;
|
|
vec3_t org;
|
|
int color;
|
|
cparticle_t *active, *tail;
|
|
|
|
active = NULL;
|
|
tail = NULL;
|
|
|
|
for (p=active_particles ; p ; p=next)
|
|
{
|
|
next = p->next;
|
|
|
|
// PMM - added INSTANT_PARTICLE handling for heat beam
|
|
if (p->alphavel != INSTANT_PARTICLE)
|
|
{
|
|
time = (cl.time - p->time)*0.001;
|
|
alpha = p->alpha + time*p->alphavel;
|
|
if (alpha <= 0)
|
|
{ // faded out
|
|
p->next = free_particles;
|
|
free_particles = p;
|
|
continue;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
alpha = p->alpha;
|
|
}
|
|
|
|
p->next = NULL;
|
|
if (!tail)
|
|
active = tail = p;
|
|
else
|
|
{
|
|
tail->next = p;
|
|
tail = p;
|
|
}
|
|
|
|
if (alpha > 1.0)
|
|
alpha = 1;
|
|
color = p->color;
|
|
|
|
time2 = time*time;
|
|
|
|
org[0] = p->org[0] + p->vel[0]*time + p->accel[0]*time2;
|
|
org[1] = p->org[1] + p->vel[1]*time + p->accel[1]*time2;
|
|
org[2] = p->org[2] + p->vel[2]*time + p->accel[2]*time2;
|
|
|
|
V_AddParticle (org, color, alpha);
|
|
// PMM
|
|
if (p->alphavel == INSTANT_PARTICLE)
|
|
{
|
|
p->alphavel = 0.0;
|
|
p->alpha = 0.0;
|
|
}
|
|
}
|
|
|
|
active_particles = active;
|
|
}
|
|
|
|
|
|
/*
|
|
==============
|
|
CL_EntityEvent
|
|
|
|
An entity has just been parsed that has an event value
|
|
|
|
the female events are there for backwards compatability
|
|
==============
|
|
*/
|
|
extern sound_t cl_sfx_footsteps[4];
|
|
|
|
void CL_EntityEvent (entity_state_t *ent)
|
|
{
|
|
switch (ent->event)
|
|
{
|
|
case EV_ITEM_RESPAWN:
|
|
S_StartSound (NULL, ent->number, CHAN_WEAPON, S_RegisterSound("items/respawn1.wav"));
|
|
CL_ItemRespawnParticles (ent->origin);
|
|
break;
|
|
case EV_PLAYER_TELEPORT:
|
|
S_StartSound (NULL, ent->number, CHAN_WEAPON, S_RegisterSound("misc/tele1.wav"));
|
|
CL_TeleportParticles (ent->origin);
|
|
break;
|
|
case EV_FOOTSTEP:
|
|
if (cl_footsteps->value)
|
|
S_StartSound (NULL, ent->number, CHAN_BODY, cl_sfx_footsteps[rand()&3]);
|
|
break;
|
|
case EV_FALLSHORT:
|
|
S_StartSound (NULL, ent->number, CHAN_AUTO, S_RegisterSound ("player/land1.wav"));
|
|
break;
|
|
case EV_FALL:
|
|
S_StartSound (NULL, ent->number, CHAN_AUTO, S_RegisterSound ("*fall2.wav"));
|
|
break;
|
|
case EV_FALLFAR:
|
|
S_StartSound (NULL, ent->number, CHAN_AUTO, S_RegisterSound ("*fall1.wav"));
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
==============
|
|
CL_ClearEffects
|
|
|
|
==============
|
|
*/
|
|
void CL_ClearEffects (void)
|
|
{
|
|
CL_ClearParticles ();
|
|
CL_ClearDlights ();
|
|
CL_ClearLightStyles ();
|
|
}
|