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)
131 int colorStart, colorLength, count;
132 float velspeed, radius;
135 type = MSG_ReadByte ();
138 case TE_WIZSPIKE: // spike hitting wall
140 R_RunParticleEffect (pos, vec3_origin, 20, 30);
141 S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
144 case TE_KNIGHTSPIKE: // spike hitting wall
146 R_RunParticleEffect (pos, vec3_origin, 226, 20);
147 S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
150 case TE_SPIKE: // spike hitting wall
152 // LordHavoc: changed to spark shower
153 R_SparkShower(pos, vec3_origin, 15);
154 //R_RunParticleEffect (pos, vec3_origin, 0, 10);
156 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
161 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
163 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
165 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
168 case TE_SPIKEQUAD: // quad spike hitting wall
170 // LordHavoc: changed to spark shower
171 R_SparkShower(pos, vec3_origin, 15);
172 //R_RunParticleEffect (pos, vec3_origin, 0, 10);
173 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
174 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
176 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
181 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
183 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
185 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
188 case TE_SUPERSPIKE: // super spike hitting wall
190 // LordHavoc: changed to dust shower
191 R_SparkShower(pos, vec3_origin, 30);
192 //R_RunParticleEffect (pos, vec3_origin, 0, 20);
194 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
199 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
201 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
203 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
206 case TE_SUPERSPIKEQUAD: // quad super spike hitting wall
208 // LordHavoc: changed to dust shower
209 R_SparkShower(pos, vec3_origin, 30);
210 //R_RunParticleEffect (pos, vec3_origin, 0, 20);
211 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
213 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
218 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
220 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
222 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
225 // LordHavoc: added for improved blood splatters
226 case TE_BLOOD: // blood puff
228 dir[0] = MSG_ReadChar ();
229 dir[1] = MSG_ReadChar ();
230 dir[2] = MSG_ReadChar ();
231 count = MSG_ReadByte (); // amount of particles
232 R_BloodPuff(pos, dir, count);
234 case TE_BLOOD2: // blood puff
236 R_BloodPuff(pos, vec3_origin, 10);
238 case TE_SPARK: // spark shower
240 dir[0] = MSG_ReadChar ();
241 dir[1] = MSG_ReadChar ();
242 dir[2] = MSG_ReadChar ();
243 count = MSG_ReadByte (); // amount of particles
244 R_SparkShower(pos, dir, count);
246 // LordHavoc: added for improved gore
247 case TE_BLOODSHOWER: // vaporized body
248 MSG_ReadVector(pos); // mins
249 MSG_ReadVector(pos2); // maxs
250 velspeed = MSG_ReadCoord (); // speed
251 count = MSG_ReadShort (); // number of particles
252 R_BloodShower(pos, pos2, velspeed, count);
254 case TE_PARTICLECUBE: // general purpose particle effect
255 MSG_ReadVector(pos); // mins
256 MSG_ReadVector(pos2); // maxs
257 MSG_ReadVector(dir); // dir
258 count = MSG_ReadShort (); // number of particles
259 colorStart = MSG_ReadByte (); // color
260 colorLength = MSG_ReadByte (); // gravity (1 or 0)
261 velspeed = MSG_ReadCoord (); // randomvel
262 R_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
265 case TE_PARTICLERAIN: // 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 R_ParticleRain(pos, pos2, dir, count, colorStart, 0);
274 case TE_PARTICLESNOW: // general purpose particle effect
275 MSG_ReadVector(pos); // mins
276 MSG_ReadVector(pos2); // maxs
277 MSG_ReadVector(dir); // dir
278 count = MSG_ReadShort (); // number of particles
279 colorStart = MSG_ReadByte (); // color
280 R_ParticleRain(pos, pos2, dir, count, colorStart, 1);
283 case TE_GUNSHOT: // bullet hitting wall
285 // LordHavoc: changed to dust shower
286 R_SparkShower(pos, vec3_origin, 15);
287 //R_RunParticleEffect (pos, vec3_origin, 0, 20);
290 case TE_GUNSHOTQUAD: // quad bullet hitting wall
292 R_SparkShower(pos, vec3_origin, 15);
293 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
296 case TE_EXPLOSION: // rocket explosion
298 FindNonSolidLocation(pos);
299 R_ParticleExplosion (pos, false);
300 // R_BlastParticles (pos, 120, 120);
301 CL_AllocDlight (NULL, pos, 350, 1.0f, 0.8f, 0.4f, 700, 0.5);
302 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
305 case TE_EXPLOSIONQUAD: // quad rocket explosion
307 FindNonSolidLocation(pos);
308 R_ParticleExplosion (pos, false);
309 // R_BlastParticles (pos, 120, 480);
310 CL_AllocDlight (NULL, pos, 600, 0.5f, 0.4f, 1.0f, 1200, 0.5);
311 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
315 case TE_SMOKEEXPLOSION: // rocket explosion with a cloud of smoke
317 FindNonSolidLocation(pos);
318 R_ParticleExplosion (pos, true);
319 CL_AllocDlight (NULL, pos, 350, 1.0f, 0.8f, 0.4f, 700, 0.5);
320 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
324 case TE_EXPLOSION3: // Nehahra movie colored lighting explosion
326 FindNonSolidLocation(pos);
327 R_ParticleExplosion (pos, false);
328 // R_BlastParticles (pos, 120, 120);
329 CL_AllocDlight (NULL, pos, 350, MSG_ReadCoord(), MSG_ReadCoord(), MSG_ReadCoord(), 700, 0.5);
330 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
333 case TE_EXPLOSIONRGB: // colored lighting explosion
335 FindNonSolidLocation(pos);
336 R_ParticleExplosion (pos, false);
337 // R_BlastParticles (pos, 120, 120);
338 CL_AllocDlight (NULL, pos, 350, MSG_ReadByte() * (1.0 / 255.0), MSG_ReadByte() * (1.0 / 255.0), MSG_ReadByte() * (1.0 / 255.0), 700, 0.5);
339 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
342 case TE_TAREXPLOSION: // tarbaby explosion
344 FindNonSolidLocation(pos);
345 R_BlobExplosion (pos);
346 // R_BlastParticles (pos, 120, 120);
348 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
349 CL_AllocDlight (NULL, pos, 600, 0.8f, 0.4f, 1.0f, 1200, 0.5);
350 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
355 FindNonSolidLocation(pos);
356 CL_AllocDlight (NULL, pos, 200, 1, 1, 1, 1000, 0.2);
361 FindNonSolidLocation(pos);
362 radius = MSG_ReadByte() * 8;
363 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
364 CL_AllocDlight (NULL, pos, radius, MSG_ReadByte() * (1.0 / 255.0), MSG_ReadByte() * (1.0 / 255.0), MSG_ReadByte() * (1.0 / 255.0), radius / velspeed, velspeed);
370 count = MSG_ReadByte();
371 R_Flames(pos, dir, count);
374 case TE_LIGHTNING1: // lightning bolts
375 CL_ParseBeam (Mod_ForName("progs/bolt.mdl", true));
378 case TE_LIGHTNING2: // lightning bolts
379 CL_ParseBeam (Mod_ForName("progs/bolt2.mdl", true));
382 case TE_LIGHTNING3: // lightning bolts
383 CL_ParseBeam (Mod_ForName("progs/bolt3.mdl", true));
387 case TE_BEAM: // grappling hook beam
388 CL_ParseBeam (Mod_ForName("progs/beam.mdl", true));
392 // LordHavoc: for compatibility with the Nehahra movie...
393 case TE_LIGHTNING4NEH:
394 CL_ParseBeam (Mod_ForName(MSG_ReadString(), true));
398 pos[0] = MSG_ReadCoord ();
399 pos[1] = MSG_ReadCoord ();
400 pos[2] = MSG_ReadCoord ();
405 pos[0] = MSG_ReadCoord ();
406 pos[1] = MSG_ReadCoord ();
407 pos[2] = MSG_ReadCoord ();
408 R_TeleportSplash (pos);
411 case TE_EXPLOSION2: // color mapped explosion
413 FindNonSolidLocation(pos);
414 colorStart = MSG_ReadByte ();
415 colorLength = MSG_ReadByte ();
416 R_ParticleExplosion2 (pos, colorStart, colorLength);
417 // R_BlastParticles (pos, 80, 80);
418 tempcolor = (byte *)&d_8to24table[(rand()%colorLength) + colorStart];
419 CL_AllocDlight (NULL, pos, 350, tempcolor[0] * (1.0f / 255.0f), tempcolor[1] * (1.0f / 255.0f), tempcolor[2] * (1.0f / 255.0f), 700, 0.5);
420 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
424 Host_Error ("CL_ParseTEnt: bad type %d", type);
434 entity_t *CL_NewTempEntity (void)
438 if (cl_numvisedicts >= MAX_VISEDICTS)
440 if (num_temp_entities >= MAX_TEMP_ENTITIES)
442 ent = &cl_temp_entities[num_temp_entities++];
443 memset (ent, 0, sizeof(*ent));
444 cl_visedicts[cl_numvisedicts++] = ent;
446 ent->render.colormap = -1; // no special coloring
447 ent->render.scale = 1;
448 ent->render.alpha = 1;
449 ent->render.colormod[0] = ent->render.colormod[1] = ent->render.colormod[2] = 1;
459 void CL_UpdateTEnts (void)
469 num_temp_entities = 0;
472 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
474 if (!b->model || b->endtime < cl.time)
477 // if coming from the player, update the start position
478 if (b->entity == cl.viewentity)
479 VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
481 // calculate pitch and yaw
482 VectorSubtract (b->end, b->start, dist);
484 if (dist[1] == 0 && dist[0] == 0)
494 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
498 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
499 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
504 // add new entities for the lightning
505 VectorCopy (b->start, org);
506 d = VectorNormalizeLength(dist);
509 ent = CL_NewTempEntity ();
512 VectorCopy (org, ent->render.origin);
513 ent->render.model = b->model;
514 ent->render.effects = EF_FULLBRIGHT;
515 ent->render.angles[0] = pitch;
516 ent->render.angles[1] = yaw;
517 ent->render.angles[2] = rand()%360;
519 if (r_glowinglightning.value > 0)
520 CL_AllocDlight(ent, ent->render.origin, lhrandom(100, 120), r_glowinglightning.value * 0.25f, r_glowinglightning.value * 0.25f, r_glowinglightning.value * 0.25f, 0, 0);
522 VectorMA(org, 30, dist, org);