2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // cl_tent.c -- client side temporary entities
24 #define MSG_ReadVector(v) {(v)[0] = MSG_ReadCoord();(v)[1] = MSG_ReadCoord();(v)[2] = MSG_ReadCoord();}
26 cvar_t r_glowinglightning = {"r_glowinglightning", "1", true};
28 int num_temp_entities;
29 entity_t cl_temp_entities[MAX_TEMP_ENTITIES];
30 beam_t cl_beams[MAX_BEAMS];
33 sfx_t *cl_sfx_knighthit;
45 void CL_InitTEnts (void)
47 Cvar_RegisterVariable(&r_glowinglightning);
48 cl_sfx_wizhit = S_PrecacheSound ("wizard/hit.wav");
49 cl_sfx_knighthit = S_PrecacheSound ("hknight/hit.wav");
50 cl_sfx_tink1 = S_PrecacheSound ("weapons/tink1.wav");
51 cl_sfx_ric1 = S_PrecacheSound ("weapons/ric1.wav");
52 cl_sfx_ric2 = S_PrecacheSound ("weapons/ric2.wav");
53 cl_sfx_ric3 = S_PrecacheSound ("weapons/ric3.wav");
54 cl_sfx_r_exp3 = S_PrecacheSound ("weapons/r_exp3.wav");
62 void CL_ParseBeam (model_t *m)
69 ent = MSG_ReadShort ();
70 MSG_ReadVector(start);
73 // override any beam with the same entity
74 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
79 b->endtime = cl.time + 0.2;
80 VectorCopy (start, b->start);
81 VectorCopy (end, b->end);
86 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
88 if (!b->model || b->endtime < cl.time)
92 b->endtime = cl.time + 0.2;
93 VectorCopy (start, b->start);
94 VectorCopy (end, b->end);
98 Con_Printf ("beam list overflow!\n");
101 //void R_BlastParticles(vec3_t org, vec_t radius, vec_t power);
102 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count);
103 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel);
104 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type);
106 // attempts to find the nearest non-solid location, used for explosions mainly
107 void FindNonSolidLocation(vec3_t pos)
109 if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
110 pos[0]-=1;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
111 pos[0]+=2;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
113 pos[1]-=1;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
114 pos[1]+=2;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
116 pos[2]-=1;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
117 pos[2]+=2;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
126 void CL_ParseTEnt (void)
134 int colorStart, colorLength, count;
138 type = MSG_ReadByte ();
141 case TE_WIZSPIKE: // spike hitting wall
143 R_RunParticleEffect (pos, vec3_origin, 20, 30);
144 S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
147 case TE_KNIGHTSPIKE: // spike hitting wall
149 R_RunParticleEffect (pos, vec3_origin, 226, 20);
150 S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
153 case TE_SPIKE: // spike hitting wall
155 // LordHavoc: changed to spark shower
156 R_SparkShower(pos, vec3_origin, 15);
157 //R_RunParticleEffect (pos, vec3_origin, 0, 10);
159 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
164 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
166 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
168 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
171 case TE_SPIKEQUAD: // quad spike hitting wall
173 // LordHavoc: changed to spark shower
174 R_SparkShower(pos, vec3_origin, 15);
175 //R_RunParticleEffect (pos, vec3_origin, 0, 10);
176 dl = CL_AllocDlight (0);
177 VectorCopy (pos, dl->origin);
179 dl->die = cl.time + 0.2;
181 dl->color[0] = 0.05;dl->color[1] = 0.05;dl->color[2] = 0.8;
182 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
184 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
189 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
191 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
193 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
196 case TE_SUPERSPIKE: // super spike hitting wall
198 // LordHavoc: changed to dust shower
199 R_SparkShower(pos, vec3_origin, 30);
200 //R_RunParticleEffect (pos, vec3_origin, 0, 20);
202 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
207 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
209 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
211 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
214 case TE_SUPERSPIKEQUAD: // quad super spike hitting wall
216 // LordHavoc: changed to dust shower
217 R_SparkShower(pos, vec3_origin, 30);
218 //R_RunParticleEffect (pos, vec3_origin, 0, 20);
219 dl = CL_AllocDlight (0);
220 VectorCopy (pos, dl->origin);
222 dl->die = cl.time + 0.2;
224 dl->color[0] = 0.05;dl->color[1] = 0.05;dl->color[2] = 0.8;
226 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
231 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
233 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
235 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
238 // LordHavoc: added for improved blood splatters
239 case TE_BLOOD: // blood puff
241 dir[0] = MSG_ReadChar ();
242 dir[1] = MSG_ReadChar ();
243 dir[2] = MSG_ReadChar ();
244 count = MSG_ReadByte (); // amount of particles
247 case TE_BLOOD2: // blood puff
251 case TE_SPARK: // spark shower
253 dir[0] = MSG_ReadChar ();
254 dir[1] = MSG_ReadChar ();
255 dir[2] = MSG_ReadChar ();
256 count = MSG_ReadByte (); // amount of particles
257 R_SparkShower(pos, dir, count);
259 // LordHavoc: added for improved gore
260 case TE_BLOODSHOWER: // vaporized body
261 MSG_ReadVector(pos); // mins
262 MSG_ReadVector(pos2); // maxs
263 velspeed = MSG_ReadCoord (); // speed
264 count = MSG_ReadShort (); // number of particles
265 R_BloodShower(pos, pos2, velspeed, count);
267 case TE_PARTICLECUBE: // general purpose particle effect
268 MSG_ReadVector(pos); // mins
269 MSG_ReadVector(pos2); // maxs
270 MSG_ReadVector(dir); // dir
271 count = MSG_ReadShort (); // number of particles
272 colorStart = MSG_ReadByte (); // color
273 colorLength = MSG_ReadByte (); // gravity (1 or 0)
274 velspeed = MSG_ReadCoord (); // randomvel
275 R_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
278 case TE_PARTICLERAIN: // general purpose particle effect
279 MSG_ReadVector(pos); // mins
280 MSG_ReadVector(pos2); // maxs
281 MSG_ReadVector(dir); // dir
282 count = MSG_ReadShort (); // number of particles
283 colorStart = MSG_ReadByte (); // color
284 R_ParticleRain(pos, pos2, dir, count, colorStart, 0);
287 case TE_PARTICLESNOW: // general purpose particle effect
288 MSG_ReadVector(pos); // mins
289 MSG_ReadVector(pos2); // maxs
290 MSG_ReadVector(dir); // dir
291 count = MSG_ReadShort (); // number of particles
292 colorStart = MSG_ReadByte (); // color
293 R_ParticleRain(pos, pos2, dir, count, colorStart, 1);
296 case TE_GUNSHOT: // bullet hitting wall
298 // LordHavoc: changed to dust shower
299 R_SparkShower(pos, vec3_origin, 15);
300 //R_RunParticleEffect (pos, vec3_origin, 0, 20);
303 case TE_GUNSHOTQUAD: // quad bullet hitting wall
305 R_SparkShower(pos, vec3_origin, 15);
306 dl = CL_AllocDlight (0);
307 VectorCopy (pos, dl->origin);
309 dl->die = cl.time + 0.2;
311 dl->color[0] = 0.05;dl->color[1] = 0.05;dl->color[2] = 0.8;
314 case TE_EXPLOSION: // rocket explosion
316 FindNonSolidLocation(pos);
317 R_ParticleExplosion (pos, false);
318 // R_BlastParticles (pos, 120, 120);
319 dl = CL_AllocDlight (0);
320 VectorCopy (pos, dl->origin);
322 dl->die = cl.time + 0.5;
324 dl->color[0] = 1.0;dl->color[1] = 0.8;dl->color[2] = 0.4;
325 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
328 case TE_EXPLOSIONQUAD: // quad rocket explosion
330 FindNonSolidLocation(pos);
331 R_ParticleExplosion (pos, false);
332 // R_BlastParticles (pos, 120, 480);
333 dl = CL_AllocDlight (0);
334 VectorCopy (pos, dl->origin);
336 dl->die = cl.time + 0.5;
338 dl->color[0] = 0.5;dl->color[1] = 0.4;dl->color[2] = 1.0;
339 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
343 case TE_SMOKEEXPLOSION: // rocket explosion with a cloud of smoke
345 FindNonSolidLocation(pos);
346 R_ParticleExplosion (pos, true);
347 dl = CL_AllocDlight (0);
348 VectorCopy (pos, dl->origin);
350 dl->die = cl.time + 0.5;
352 dl->color[0] = 1.0;dl->color[1] = 0.8;dl->color[2] = 0.4;
353 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
357 case TE_EXPLOSION3: // Nehahra movie colored lighting explosion
359 FindNonSolidLocation(pos);
360 R_ParticleExplosion (pos, false);
361 // R_BlastParticles (pos, 120, 120);
362 dl = CL_AllocDlight (0);
363 VectorCopy (pos, dl->origin);
365 dl->die = cl.time + 0.5;
367 dl->color[0] = MSG_ReadCoord();dl->color[1] = MSG_ReadCoord();dl->color[2] = MSG_ReadCoord();
368 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
371 case TE_EXPLOSIONRGB: // colored lighting explosion
373 FindNonSolidLocation(pos);
374 R_ParticleExplosion (pos, false);
375 // R_BlastParticles (pos, 120, 120);
376 dl = CL_AllocDlight (0);
377 VectorCopy (pos, dl->origin);
379 dl->die = cl.time + 0.5;
381 dl->color[0] = MSG_ReadByte() * (1.0 / 255.0);dl->color[1] = MSG_ReadByte() * (1.0 / 255.0);dl->color[2] = MSG_ReadByte() * (1.0 / 255.0);
382 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
385 case TE_TAREXPLOSION: // tarbaby explosion
387 FindNonSolidLocation(pos);
388 R_BlobExplosion (pos);
389 // R_BlastParticles (pos, 120, 120);
391 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
392 dl = CL_AllocDlight (0);
393 VectorCopy (pos, dl->origin);
395 dl->die = cl.time + 0.5;
397 dl->color[0] = 0.8;dl->color[1] = 0.4;dl->color[2] = 1.0;
398 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
401 case TE_LIGHTNING1: // lightning bolts
402 CL_ParseBeam (Mod_ForName("progs/bolt.mdl", true));
405 case TE_LIGHTNING2: // lightning bolts
406 CL_ParseBeam (Mod_ForName("progs/bolt2.mdl", true));
409 case TE_LIGHTNING3: // lightning bolts
410 CL_ParseBeam (Mod_ForName("progs/bolt3.mdl", true));
414 case TE_BEAM: // grappling hook beam
415 CL_ParseBeam (Mod_ForName("progs/beam.mdl", true));
419 // LordHavoc: for compatibility with the Nehahra movie...
420 case TE_LIGHTNING4NEH:
421 CL_ParseBeam (Mod_ForName(MSG_ReadString(), true));
425 pos[0] = MSG_ReadCoord ();
426 pos[1] = MSG_ReadCoord ();
427 pos[2] = MSG_ReadCoord ();
432 pos[0] = MSG_ReadCoord ();
433 pos[1] = MSG_ReadCoord ();
434 pos[2] = MSG_ReadCoord ();
435 R_TeleportSplash (pos);
438 case TE_EXPLOSION2: // color mapped explosion
440 FindNonSolidLocation(pos);
441 colorStart = MSG_ReadByte ();
442 colorLength = MSG_ReadByte ();
443 R_ParticleExplosion2 (pos, colorStart, colorLength);
444 // R_BlastParticles (pos, 80, 80);
445 dl = CL_AllocDlight (0);
446 VectorCopy (pos, dl->origin);
448 dl->die = cl.time + 0.5;
450 tempcolor = (byte *)&d_8to24table[(rand()%colorLength) + colorStart];
451 dl->color[0] = tempcolor[0] * (1.0f / 255.0f);dl->color[1] = tempcolor[1] * (1.0f / 255.0f);dl->color[2] = tempcolor[2] * (1.0f / 255.0f);
452 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
456 Host_Error ("CL_ParseTEnt: bad type %d", type);
466 entity_t *CL_NewTempEntity (void)
470 if (cl_numvisedicts == MAX_VISEDICTS)
472 if (num_temp_entities == MAX_TEMP_ENTITIES)
474 ent = &cl_temp_entities[num_temp_entities];
475 memset (ent, 0, sizeof(*ent));
477 cl_visedicts[cl_numvisedicts] = ent;
480 ent->colormap = -1; // no special coloring
483 ent->colormod[0] = ent->colormod[1] = ent->colormod[2] = 1;
493 void CL_UpdateTEnts (void)
504 num_temp_entities = 0;
507 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
509 if (!b->model || b->endtime < cl.time)
512 // if coming from the player, update the start position
513 if (b->entity == cl.viewentity)
515 VectorCopy (cl_entities[cl.viewentity].origin, b->start);
518 // calculate pitch and yaw
519 VectorSubtract (b->end, b->start, dist);
521 if (dist[1] == 0 && dist[0] == 0)
531 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
535 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
536 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
541 // add new entities for the lightning
542 VectorCopy (b->start, org);
543 d = VectorNormalizeLength(dist);
546 ent = CL_NewTempEntity ();
549 VectorCopy (org, ent->origin);
550 ent->model = b->model;
551 ent->effects = EF_FULLBRIGHT;
552 ent->angles[0] = pitch;
553 ent->angles[1] = yaw;
554 ent->angles[2] = rand()%360;
556 if (r_glowinglightning.value)
558 dl = CL_AllocDlight (0);
559 VectorCopy (ent->origin, dl->origin);
560 dl->radius = 100 + (rand()&31);
561 dl->die = cl.time + 0.001;
562 dl->color[0] = 1;dl->color[1] = 1;dl->color[2] = 1;
565 VectorMA(org, 30, dist, org);