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 cl_glowinglightning = {CVAR_SAVE, "cl_glowinglightning", "1"};
26 int num_temp_entities;
27 entity_t cl_temp_entities[MAX_TEMP_ENTITIES];
28 beam_t cl_beams[MAX_BEAMS];
30 model_t *cl_model_bolt = NULL;
31 model_t *cl_model_bolt2 = NULL;
32 model_t *cl_model_bolt3 = NULL;
33 model_t *cl_model_beam = NULL;
36 sfx_t *cl_sfx_knighthit;
48 void CL_InitTEnts (void)
50 Cvar_RegisterVariable(&cl_glowinglightning);
51 cl_sfx_wizhit = S_PrecacheSound ("wizard/hit.wav");
52 cl_sfx_knighthit = S_PrecacheSound ("hknight/hit.wav");
53 cl_sfx_tink1 = S_PrecacheSound ("weapons/tink1.wav");
54 cl_sfx_ric1 = S_PrecacheSound ("weapons/ric1.wav");
55 cl_sfx_ric2 = S_PrecacheSound ("weapons/ric2.wav");
56 cl_sfx_ric3 = S_PrecacheSound ("weapons/ric3.wav");
57 cl_sfx_r_exp3 = S_PrecacheSound ("weapons/r_exp3.wav");
65 void CL_ParseBeam (model_t *m)
72 ent = MSG_ReadShort ();
73 MSG_ReadVector(start);
76 // override any beam with the same entity
77 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
82 b->endtime = cl.time + 0.2;
83 VectorCopy (start, b->start);
84 VectorCopy (end, b->end);
89 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
91 if (!b->model || b->endtime < cl.time)
95 b->endtime = cl.time + 0.2;
96 VectorCopy (start, b->start);
97 VectorCopy (end, b->end);
101 Con_Printf ("beam list overflow!\n");
110 void CL_ParseTEnt (void)
118 int colorStart, colorLength, count;
119 float velspeed, radius;
122 type = MSG_ReadByte ();
125 case TE_WIZSPIKE: // spike hitting wall
127 CL_RunParticleEffect (pos, vec3_origin, 20, 30);
128 S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
131 case TE_KNIGHTSPIKE: // spike hitting wall
133 CL_RunParticleEffect (pos, vec3_origin, 226, 20);
134 S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
137 case TE_SPIKE: // spike hitting wall
139 // LordHavoc: changed to spark shower
140 CL_SparkShower(pos, vec3_origin, 15);
141 //CL_RunParticleEffect (pos, vec3_origin, 0, 10);
143 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
148 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
150 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
152 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
155 case TE_SPIKEQUAD: // quad spike hitting wall
157 // LordHavoc: changed to spark shower
158 CL_SparkShower(pos, vec3_origin, 15);
159 //CL_RunParticleEffect (pos, vec3_origin, 0, 10);
160 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
161 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
163 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
168 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
170 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
172 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
175 case TE_SUPERSPIKE: // super spike hitting wall
177 // LordHavoc: changed to dust shower
178 CL_SparkShower(pos, vec3_origin, 30);
179 //CL_RunParticleEffect (pos, vec3_origin, 0, 20);
181 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
186 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
188 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
190 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
193 case TE_SUPERSPIKEQUAD: // quad super spike hitting wall
195 // LordHavoc: changed to dust shower
196 CL_SparkShower(pos, vec3_origin, 30);
197 //CL_RunParticleEffect (pos, vec3_origin, 0, 20);
198 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
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 // LordHavoc: added for improved blood splatters
213 case TE_BLOOD: // blood puff
215 dir[0] = MSG_ReadChar ();
216 dir[1] = MSG_ReadChar ();
217 dir[2] = MSG_ReadChar ();
218 count = MSG_ReadByte (); // amount of particles
219 CL_BloodPuff(pos, dir, count);
221 case TE_BLOOD2: // blood puff
223 CL_BloodPuff(pos, vec3_origin, 10);
225 case TE_SPARK: // spark shower
227 dir[0] = MSG_ReadChar ();
228 dir[1] = MSG_ReadChar ();
229 dir[2] = MSG_ReadChar ();
230 count = MSG_ReadByte (); // amount of particles
231 CL_SparkShower(pos, dir, count);
233 // LordHavoc: added for improved gore
234 case TE_BLOODSHOWER: // vaporized body
235 MSG_ReadVector(pos); // mins
236 MSG_ReadVector(pos2); // maxs
237 velspeed = MSG_ReadCoord (); // speed
238 count = MSG_ReadShort (); // number of particles
239 CL_BloodShower(pos, pos2, velspeed, count);
241 case TE_PARTICLECUBE: // general purpose particle effect
242 MSG_ReadVector(pos); // mins
243 MSG_ReadVector(pos2); // maxs
244 MSG_ReadVector(dir); // dir
245 count = MSG_ReadShort (); // number of particles
246 colorStart = MSG_ReadByte (); // color
247 colorLength = MSG_ReadByte (); // gravity (1 or 0)
248 velspeed = MSG_ReadCoord (); // randomvel
249 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
252 case TE_PARTICLERAIN: // general purpose particle effect
253 MSG_ReadVector(pos); // mins
254 MSG_ReadVector(pos2); // maxs
255 MSG_ReadVector(dir); // dir
256 count = MSG_ReadShort (); // number of particles
257 colorStart = MSG_ReadByte (); // color
258 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
261 case TE_PARTICLESNOW: // general purpose particle effect
262 MSG_ReadVector(pos); // mins
263 MSG_ReadVector(pos2); // maxs
264 MSG_ReadVector(dir); // dir
265 count = MSG_ReadShort (); // number of particles
266 colorStart = MSG_ReadByte (); // color
267 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
270 case TE_GUNSHOT: // bullet hitting wall
272 // LordHavoc: changed to dust shower
273 CL_SparkShower(pos, vec3_origin, 15);
274 //CL_RunParticleEffect (pos, vec3_origin, 0, 20);
277 case TE_GUNSHOTQUAD: // quad bullet hitting wall
279 CL_SparkShower(pos, vec3_origin, 15);
280 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
283 case TE_EXPLOSION: // rocket explosion
285 Mod_FindNonSolidLocation(pos, cl.worldmodel);
286 CL_ParticleExplosion (pos, false);
287 // CL_BlastParticles (pos, 120, 120);
288 CL_AllocDlight (NULL, pos, 350, 1.0f, 0.8f, 0.4f, 700, 0.5);
289 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
292 case TE_EXPLOSIONQUAD: // quad rocket explosion
294 Mod_FindNonSolidLocation(pos, cl.worldmodel);
295 CL_ParticleExplosion (pos, false);
296 // CL_BlastParticles (pos, 120, 480);
297 CL_AllocDlight (NULL, pos, 600, 0.5f, 0.4f, 1.0f, 1200, 0.5);
298 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
302 case TE_SMOKEEXPLOSION: // rocket explosion with a cloud of smoke
304 Mod_FindNonSolidLocation(pos, cl.worldmodel);
305 CL_ParticleExplosion (pos, true);
306 CL_AllocDlight (NULL, pos, 350, 1.0f, 0.8f, 0.4f, 700, 0.5);
307 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
311 case TE_EXPLOSION3: // Nehahra movie colored lighting explosion
313 Mod_FindNonSolidLocation(pos, cl.worldmodel);
314 CL_ParticleExplosion (pos, false);
315 // CL_BlastParticles (pos, 120, 120);
316 CL_AllocDlight (NULL, pos, 350, MSG_ReadCoord(), MSG_ReadCoord(), MSG_ReadCoord(), 700, 0.5);
317 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
320 case TE_EXPLOSIONRGB: // colored lighting explosion
322 Mod_FindNonSolidLocation(pos, cl.worldmodel);
323 CL_ParticleExplosion (pos, false);
324 // CL_BlastParticles (pos, 120, 120);
325 color[0] = MSG_ReadByte() * (1.0 / 255.0);
326 color[1] = MSG_ReadByte() * (1.0 / 255.0);
327 color[2] = MSG_ReadByte() * (1.0 / 255.0);
328 CL_AllocDlight (NULL, pos, 350, color[0], color[1], color[2], 700, 0.5);
329 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
332 case TE_TAREXPLOSION: // tarbaby explosion
334 Mod_FindNonSolidLocation(pos, cl.worldmodel);
335 CL_BlobExplosion (pos);
336 // CL_BlastParticles (pos, 120, 120);
338 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
339 CL_AllocDlight (NULL, pos, 600, 0.8f, 0.4f, 1.0f, 1200, 0.5);
340 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
345 Mod_FindNonSolidLocation(pos, cl.worldmodel);
346 CL_AllocDlight (NULL, pos, 200, 1, 1, 1, 1000, 0.2);
351 Mod_FindNonSolidLocation(pos, cl.worldmodel);
352 radius = MSG_ReadByte() * 8;
353 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
354 color[0] = MSG_ReadByte() * (1.0 / 255.0);
355 color[1] = MSG_ReadByte() * (1.0 / 255.0);
356 color[2] = MSG_ReadByte() * (1.0 / 255.0);
357 CL_AllocDlight (NULL, pos, radius, color[0], color[1], color[2], radius / velspeed, velspeed);
363 count = MSG_ReadByte();
364 CL_Flames(pos, dir, count);
367 case TE_LIGHTNING1: // lightning bolts
369 cl_model_bolt = Mod_ForName("progs/bolt.mdl", true, true, false);
370 CL_ParseBeam (cl_model_bolt);
373 case TE_LIGHTNING2: // lightning bolts
375 cl_model_bolt2 = Mod_ForName("progs/bolt2.mdl", true, true, false);
376 CL_ParseBeam (cl_model_bolt2);
379 case TE_LIGHTNING3: // lightning bolts
381 cl_model_bolt3 = Mod_ForName("progs/bolt3.mdl", true, true, false);
382 CL_ParseBeam (cl_model_bolt3);
386 case TE_BEAM: // grappling hook beam
388 cl_model_beam = Mod_ForName("progs/beam.mdl", true, true, false);
389 CL_ParseBeam (cl_model_beam);
393 // LordHavoc: for compatibility with the Nehahra movie...
394 case TE_LIGHTNING4NEH:
395 CL_ParseBeam (Mod_ForName(MSG_ReadString(), true, false, false));
399 pos[0] = MSG_ReadCoord ();
400 pos[1] = MSG_ReadCoord ();
401 pos[2] = MSG_ReadCoord ();
406 pos[0] = MSG_ReadCoord ();
407 pos[1] = MSG_ReadCoord ();
408 pos[2] = MSG_ReadCoord ();
409 CL_TeleportSplash (pos);
412 case TE_EXPLOSION2: // color mapped explosion
414 Mod_FindNonSolidLocation(pos, cl.worldmodel);
415 colorStart = MSG_ReadByte ();
416 colorLength = MSG_ReadByte ();
417 CL_ParticleExplosion2 (pos, colorStart, colorLength);
418 // CL_BlastParticles (pos, 80, 80);
419 tempcolor = (byte *)&d_8to24table[(rand()%colorLength) + colorStart];
420 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);
421 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
425 Host_Error ("CL_ParseTEnt: bad type %d", type);
435 entity_t *CL_NewTempEntity (void)
439 if (r_refdef.numentities >= MAX_VISEDICTS)
441 if (num_temp_entities >= MAX_TEMP_ENTITIES)
443 ent = &cl_temp_entities[num_temp_entities++];
444 memset (ent, 0, sizeof(*ent));
445 r_refdef.entities[r_refdef.numentities++] = &ent->render;
447 ent->render.colormap = -1; // no special coloring
448 ent->render.scale = 1;
449 ent->render.alpha = 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 (cl_glowinglightning.value > 0)
520 CL_AllocDlight(&ent->render, ent->render.origin, lhrandom(200, 240), cl_glowinglightning.value * 0.25f, cl_glowinglightning.value * 0.25f, cl_glowinglightning.value * 0.25f, 0, 0);
522 VectorMA(org, 30, dist, org);