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 cvar_t r_glowinglightning = {"r_glowinglightning", "1", true};
26 int num_temp_entities;
27 entity_t cl_temp_entities[MAX_TEMP_ENTITIES];
28 beam_t cl_beams[MAX_BEAMS];
31 sfx_t *cl_sfx_knighthit;
43 void CL_InitTEnts (void)
45 Cvar_RegisterVariable(&r_glowinglightning);
46 cl_sfx_wizhit = S_PrecacheSound ("wizard/hit.wav");
47 cl_sfx_knighthit = S_PrecacheSound ("hknight/hit.wav");
48 cl_sfx_tink1 = S_PrecacheSound ("weapons/tink1.wav");
49 cl_sfx_ric1 = S_PrecacheSound ("weapons/ric1.wav");
50 cl_sfx_ric2 = S_PrecacheSound ("weapons/ric2.wav");
51 cl_sfx_ric3 = S_PrecacheSound ("weapons/ric3.wav");
52 cl_sfx_r_exp3 = S_PrecacheSound ("weapons/r_exp3.wav");
60 void CL_ParseBeam (model_t *m)
67 ent = MSG_ReadShort ();
68 MSG_ReadVector(start);
71 // override any beam with the same entity
72 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
77 b->endtime = cl.time + 0.2;
78 VectorCopy (start, b->start);
79 VectorCopy (end, b->end);
84 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
86 if (!b->model || b->endtime < cl.time)
90 b->endtime = cl.time + 0.2;
91 VectorCopy (start, b->start);
92 VectorCopy (end, b->end);
96 Con_Printf ("beam list overflow!\n");
99 //void R_BlastParticles(vec3_t org, vec_t radius, vec_t power);
100 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count);
101 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel);
102 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type);
104 // attempts to find the nearest non-solid location, used for explosions mainly
105 void FindNonSolidLocation(vec3_t pos)
107 if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
108 pos[0]-=1;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
109 pos[0]+=2;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
111 pos[1]-=1;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
112 pos[1]+=2;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
114 pos[2]-=1;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
115 pos[2]+=2;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
124 void CL_ParseTEnt (void)
132 int colorStart, colorLength, count;
136 type = MSG_ReadByte ();
139 case TE_WIZSPIKE: // spike hitting wall
141 R_RunParticleEffect (pos, vec3_origin, 20, 30);
142 S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
145 case TE_KNIGHTSPIKE: // spike hitting wall
147 R_RunParticleEffect (pos, vec3_origin, 226, 20);
148 S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
151 case TE_SPIKE: // spike hitting wall
153 // LordHavoc: changed to spark shower
154 R_SparkShower(pos, vec3_origin, 15);
155 //R_RunParticleEffect (pos, vec3_origin, 0, 10);
157 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
162 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
164 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
166 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
169 case TE_SPIKEQUAD: // quad spike hitting wall
171 // LordHavoc: changed to spark shower
172 R_SparkShower(pos, vec3_origin, 15);
173 //R_RunParticleEffect (pos, vec3_origin, 0, 10);
174 dl = CL_AllocDlight (0);
175 VectorCopy (pos, dl->origin);
177 dl->die = cl.time + 0.2;
179 dl->color[0] = 0.05;dl->color[1] = 0.05;dl->color[2] = 0.8;
180 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
182 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
187 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
189 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
191 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
194 case TE_SUPERSPIKE: // super spike hitting wall
196 // LordHavoc: changed to dust shower
197 R_SparkShower(pos, vec3_origin, 30);
198 //R_RunParticleEffect (pos, vec3_origin, 0, 20);
200 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
205 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
207 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
209 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
212 case TE_SUPERSPIKEQUAD: // quad super spike hitting wall
214 // LordHavoc: changed to dust shower
215 R_SparkShower(pos, vec3_origin, 30);
216 //R_RunParticleEffect (pos, vec3_origin, 0, 20);
217 dl = CL_AllocDlight (0);
218 VectorCopy (pos, dl->origin);
220 dl->die = cl.time + 0.2;
222 dl->color[0] = 0.05;dl->color[1] = 0.05;dl->color[2] = 0.8;
224 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
229 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
231 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
233 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
236 // LordHavoc: added for improved blood splatters
237 case TE_BLOOD: // blood puff
239 dir[0] = MSG_ReadChar ();
240 dir[1] = MSG_ReadChar ();
241 dir[2] = MSG_ReadChar ();
242 count = MSG_ReadByte (); // amount of particles
243 R_BloodPuff(pos, dir, count);
245 case TE_BLOOD2: // blood puff
247 R_BloodPuff(pos, vec3_origin, 10);
249 case TE_SPARK: // spark shower
251 dir[0] = MSG_ReadChar ();
252 dir[1] = MSG_ReadChar ();
253 dir[2] = MSG_ReadChar ();
254 count = MSG_ReadByte (); // amount of particles
255 R_SparkShower(pos, dir, count);
257 // LordHavoc: added for improved gore
258 case TE_BLOODSHOWER: // vaporized body
259 MSG_ReadVector(pos); // mins
260 MSG_ReadVector(pos2); // maxs
261 velspeed = MSG_ReadCoord (); // speed
262 count = MSG_ReadShort (); // number of particles
263 R_BloodShower(pos, pos2, velspeed, count);
265 case TE_PARTICLECUBE: // general purpose particle effect
266 MSG_ReadVector(pos); // mins
267 MSG_ReadVector(pos2); // maxs
268 MSG_ReadVector(dir); // dir
269 count = MSG_ReadShort (); // number of particles
270 colorStart = MSG_ReadByte (); // color
271 colorLength = MSG_ReadByte (); // gravity (1 or 0)
272 velspeed = MSG_ReadCoord (); // randomvel
273 R_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
276 case TE_PARTICLERAIN: // general purpose particle effect
277 MSG_ReadVector(pos); // mins
278 MSG_ReadVector(pos2); // maxs
279 MSG_ReadVector(dir); // dir
280 count = MSG_ReadShort (); // number of particles
281 colorStart = MSG_ReadByte (); // color
282 R_ParticleRain(pos, pos2, dir, count, colorStart, 0);
285 case TE_PARTICLESNOW: // general purpose particle effect
286 MSG_ReadVector(pos); // mins
287 MSG_ReadVector(pos2); // maxs
288 MSG_ReadVector(dir); // dir
289 count = MSG_ReadShort (); // number of particles
290 colorStart = MSG_ReadByte (); // color
291 R_ParticleRain(pos, pos2, dir, count, colorStart, 1);
294 case TE_GUNSHOT: // bullet hitting wall
296 // LordHavoc: changed to dust shower
297 R_SparkShower(pos, vec3_origin, 15);
298 //R_RunParticleEffect (pos, vec3_origin, 0, 20);
301 case TE_GUNSHOTQUAD: // quad bullet hitting wall
303 R_SparkShower(pos, vec3_origin, 15);
304 dl = CL_AllocDlight (0);
305 VectorCopy (pos, dl->origin);
307 dl->die = cl.time + 0.2;
309 dl->color[0] = 0.05;dl->color[1] = 0.05;dl->color[2] = 0.8;
312 case TE_EXPLOSION: // rocket explosion
314 FindNonSolidLocation(pos);
315 R_ParticleExplosion (pos, false);
316 // R_BlastParticles (pos, 120, 120);
317 dl = CL_AllocDlight (0);
318 VectorCopy (pos, dl->origin);
320 dl->die = cl.time + 0.5;
322 dl->color[0] = 1.0;dl->color[1] = 0.8;dl->color[2] = 0.4;
323 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
326 case TE_EXPLOSIONQUAD: // quad rocket explosion
328 FindNonSolidLocation(pos);
329 R_ParticleExplosion (pos, false);
330 // R_BlastParticles (pos, 120, 480);
331 dl = CL_AllocDlight (0);
332 VectorCopy (pos, dl->origin);
334 dl->die = cl.time + 0.5;
336 dl->color[0] = 0.5;dl->color[1] = 0.4;dl->color[2] = 1.0;
337 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
341 case TE_SMOKEEXPLOSION: // rocket explosion with a cloud of smoke
343 FindNonSolidLocation(pos);
344 R_ParticleExplosion (pos, true);
345 dl = CL_AllocDlight (0);
346 VectorCopy (pos, dl->origin);
348 dl->die = cl.time + 0.5;
350 dl->color[0] = 1.0;dl->color[1] = 0.8;dl->color[2] = 0.4;
351 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
355 case TE_EXPLOSION3: // Nehahra movie colored lighting explosion
357 FindNonSolidLocation(pos);
358 R_ParticleExplosion (pos, false);
359 // R_BlastParticles (pos, 120, 120);
360 dl = CL_AllocDlight (0);
361 VectorCopy (pos, dl->origin);
363 dl->die = cl.time + 0.5;
365 dl->color[0] = MSG_ReadCoord();dl->color[1] = MSG_ReadCoord();dl->color[2] = MSG_ReadCoord();
366 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
369 case TE_EXPLOSIONRGB: // colored lighting explosion
371 FindNonSolidLocation(pos);
372 R_ParticleExplosion (pos, false);
373 // R_BlastParticles (pos, 120, 120);
374 dl = CL_AllocDlight (0);
375 VectorCopy (pos, dl->origin);
377 dl->die = cl.time + 0.5;
379 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);
380 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
383 case TE_TAREXPLOSION: // tarbaby explosion
385 FindNonSolidLocation(pos);
386 R_BlobExplosion (pos);
387 // R_BlastParticles (pos, 120, 120);
389 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
390 dl = CL_AllocDlight (0);
391 VectorCopy (pos, dl->origin);
393 dl->die = cl.time + 0.5;
395 dl->color[0] = 0.8;dl->color[1] = 0.4;dl->color[2] = 1.0;
396 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
401 FindNonSolidLocation(pos);
402 dl = CL_AllocDlight (0);
403 VectorCopy (pos, dl->origin);
405 dl->die = cl.time + 0.2;
407 dl->color[0] = dl->color[1] = dl->color[2] = 1;
412 FindNonSolidLocation(pos);
413 dl = CL_AllocDlight (0);
414 VectorCopy (pos, dl->origin);
415 dl->radius = MSG_ReadByte() * 8;
416 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
417 dl->die = cl.time + velspeed;
418 dl->decay = dl->radius / velspeed;
419 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);
425 count = MSG_ReadByte();
426 R_Flames(pos, dir, count);
429 case TE_LIGHTNING1: // lightning bolts
430 CL_ParseBeam (Mod_ForName("progs/bolt.mdl", true));
433 case TE_LIGHTNING2: // lightning bolts
434 CL_ParseBeam (Mod_ForName("progs/bolt2.mdl", true));
437 case TE_LIGHTNING3: // lightning bolts
438 CL_ParseBeam (Mod_ForName("progs/bolt3.mdl", true));
442 case TE_BEAM: // grappling hook beam
443 CL_ParseBeam (Mod_ForName("progs/beam.mdl", true));
447 // LordHavoc: for compatibility with the Nehahra movie...
448 case TE_LIGHTNING4NEH:
449 CL_ParseBeam (Mod_ForName(MSG_ReadString(), true));
453 pos[0] = MSG_ReadCoord ();
454 pos[1] = MSG_ReadCoord ();
455 pos[2] = MSG_ReadCoord ();
460 pos[0] = MSG_ReadCoord ();
461 pos[1] = MSG_ReadCoord ();
462 pos[2] = MSG_ReadCoord ();
463 R_TeleportSplash (pos);
466 case TE_EXPLOSION2: // color mapped explosion
468 FindNonSolidLocation(pos);
469 colorStart = MSG_ReadByte ();
470 colorLength = MSG_ReadByte ();
471 R_ParticleExplosion2 (pos, colorStart, colorLength);
472 // R_BlastParticles (pos, 80, 80);
473 dl = CL_AllocDlight (0);
474 VectorCopy (pos, dl->origin);
476 dl->die = cl.time + 0.5;
478 tempcolor = (byte *)&d_8to24table[(rand()%colorLength) + colorStart];
479 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);
480 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
484 Host_Error ("CL_ParseTEnt: bad type %d", type);
494 entity_t *CL_NewTempEntity (void)
498 if (cl_numvisedicts >= MAX_VISEDICTS)
500 if (num_temp_entities >= MAX_TEMP_ENTITIES)
502 ent = &cl_temp_entities[num_temp_entities++];
503 memset (ent, 0, sizeof(*ent));
504 cl_visedicts[cl_numvisedicts++] = ent;
506 ent->colormap = -1; // no special coloring
509 ent->colormod[0] = ent->colormod[1] = ent->colormod[2] = 1;
519 void CL_UpdateTEnts (void)
530 num_temp_entities = 0;
533 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
535 if (!b->model || b->endtime < cl.time)
538 // if coming from the player, update the start position
539 if (b->entity == cl.viewentity)
541 VectorCopy (cl_entities[cl.viewentity].origin, b->start);
544 // calculate pitch and yaw
545 VectorSubtract (b->end, b->start, dist);
547 if (dist[1] == 0 && dist[0] == 0)
557 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
561 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
562 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
567 // add new entities for the lightning
568 VectorCopy (b->start, org);
569 d = VectorNormalizeLength(dist);
572 ent = CL_NewTempEntity ();
575 VectorCopy (org, ent->origin);
576 ent->model = b->model;
577 ent->effects = EF_FULLBRIGHT;
578 ent->angles[0] = pitch;
579 ent->angles[1] = yaw;
580 ent->angles[2] = rand()%360;
582 if (r_glowinglightning.value)
584 dl = CL_AllocDlight (0);
585 VectorCopy (ent->origin, dl->origin);
586 dl->radius = 100 + (rand()&31);
587 dl->die = cl.time + 0.001;
588 dl->color[0] = dl->color[1] = dl->color[2] = r_glowinglightning.value * 0.25f;
591 VectorMA(org, 30, dist, org);