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 int num_temp_entities;
25 entity_t cl_temp_entities[MAX_TEMP_ENTITIES];
26 beam_t cl_beams[MAX_BEAMS];
28 model_t *cl_model_bolt = NULL;
29 model_t *cl_model_bolt2 = NULL;
30 model_t *cl_model_bolt3 = NULL;
31 model_t *cl_model_beam = NULL;
34 sfx_t *cl_sfx_knighthit;
46 void CL_InitTEnts (void)
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");
107 void CL_ParseTEnt (void)
115 int colorStart, colorLength, count;
116 float velspeed, radius;
119 type = MSG_ReadByte ();
122 case TE_WIZSPIKE: // spike hitting wall
124 CL_RunParticleEffect (pos, vec3_origin, 20, 30);
125 S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
128 case TE_KNIGHTSPIKE: // spike hitting wall
130 CL_RunParticleEffect (pos, vec3_origin, 226, 20);
131 S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
134 case TE_SPIKE: // spike hitting wall
136 // LordHavoc: changed to spark shower
137 CL_SparkShower(pos, vec3_origin, 15);
138 //CL_RunParticleEffect (pos, vec3_origin, 0, 10);
140 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
145 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
147 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
149 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
152 case TE_SPIKEQUAD: // quad spike hitting wall
154 // LordHavoc: changed to spark shower
155 CL_SparkShower(pos, vec3_origin, 15);
156 //CL_RunParticleEffect (pos, vec3_origin, 0, 10);
157 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
158 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
160 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
165 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
167 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
169 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
172 case TE_SUPERSPIKE: // super spike hitting wall
174 // LordHavoc: changed to dust shower
175 CL_SparkShower(pos, vec3_origin, 30);
176 //CL_RunParticleEffect (pos, vec3_origin, 0, 20);
178 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
183 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
185 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
187 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
190 case TE_SUPERSPIKEQUAD: // quad super spike hitting wall
192 // LordHavoc: changed to dust shower
193 CL_SparkShower(pos, vec3_origin, 30);
194 //CL_RunParticleEffect (pos, vec3_origin, 0, 20);
195 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
197 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
202 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
204 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
206 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
209 // LordHavoc: added for improved blood splatters
210 case TE_BLOOD: // blood puff
212 dir[0] = MSG_ReadChar ();
213 dir[1] = MSG_ReadChar ();
214 dir[2] = MSG_ReadChar ();
215 count = MSG_ReadByte (); // amount of particles
216 CL_BloodPuff(pos, dir, count);
218 case TE_BLOOD2: // blood puff
220 CL_BloodPuff(pos, vec3_origin, 10);
222 case TE_SPARK: // spark shower
224 dir[0] = MSG_ReadChar ();
225 dir[1] = MSG_ReadChar ();
226 dir[2] = MSG_ReadChar ();
227 count = MSG_ReadByte (); // amount of particles
228 CL_SparkShower(pos, dir, count);
230 // LordHavoc: added for improved gore
231 case TE_BLOODSHOWER: // vaporized body
232 MSG_ReadVector(pos); // mins
233 MSG_ReadVector(pos2); // maxs
234 velspeed = MSG_ReadCoord (); // speed
235 count = MSG_ReadShort (); // number of particles
236 CL_BloodShower(pos, pos2, velspeed, count);
238 case TE_PARTICLECUBE: // general purpose particle effect
239 MSG_ReadVector(pos); // mins
240 MSG_ReadVector(pos2); // maxs
241 MSG_ReadVector(dir); // dir
242 count = MSG_ReadShort (); // number of particles
243 colorStart = MSG_ReadByte (); // color
244 colorLength = MSG_ReadByte (); // gravity (1 or 0)
245 velspeed = MSG_ReadCoord (); // randomvel
246 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
249 case TE_PARTICLERAIN: // general purpose particle effect
250 MSG_ReadVector(pos); // mins
251 MSG_ReadVector(pos2); // maxs
252 MSG_ReadVector(dir); // dir
253 count = MSG_ReadShort (); // number of particles
254 colorStart = MSG_ReadByte (); // color
255 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
258 case TE_PARTICLESNOW: // general purpose particle effect
259 MSG_ReadVector(pos); // mins
260 MSG_ReadVector(pos2); // maxs
261 MSG_ReadVector(dir); // dir
262 count = MSG_ReadShort (); // number of particles
263 colorStart = MSG_ReadByte (); // color
264 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
267 case TE_GUNSHOT: // bullet hitting wall
269 // LordHavoc: changed to dust shower
270 CL_SparkShower(pos, vec3_origin, 15);
271 //CL_RunParticleEffect (pos, vec3_origin, 0, 20);
274 case TE_GUNSHOTQUAD: // quad bullet hitting wall
276 CL_SparkShower(pos, vec3_origin, 15);
277 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
280 case TE_EXPLOSION: // rocket explosion
282 Mod_FindNonSolidLocation(pos, cl.worldmodel);
283 CL_ParticleExplosion (pos, false);
284 // CL_BlastParticles (pos, 120, 120);
285 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
286 CL_AllocDlight (NULL, pos, 350, 1.25f, 1.0f, 0.5f, 700, 0.5);
287 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
290 case TE_EXPLOSIONQUAD: // quad rocket explosion
292 Mod_FindNonSolidLocation(pos, cl.worldmodel);
293 CL_ParticleExplosion (pos, false);
294 // CL_BlastParticles (pos, 120, 480);
295 CL_AllocDlight (NULL, pos, 600, 0.5f, 0.4f, 1.0f, 1200, 0.5);
296 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
300 case TE_SMOKEEXPLOSION: // rocket explosion with a cloud of smoke
302 Mod_FindNonSolidLocation(pos, cl.worldmodel);
303 CL_ParticleExplosion (pos, true);
304 CL_AllocDlight (NULL, pos, 350, 1.0f, 0.8f, 0.4f, 700, 0.5);
305 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
309 case TE_EXPLOSION3: // Nehahra movie colored lighting explosion
311 Mod_FindNonSolidLocation(pos, cl.worldmodel);
312 CL_ParticleExplosion (pos, false);
313 // CL_BlastParticles (pos, 120, 120);
314 CL_AllocDlight (NULL, pos, 350, MSG_ReadCoord(), MSG_ReadCoord(), MSG_ReadCoord(), 700, 0.5);
315 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
318 case TE_EXPLOSIONRGB: // colored lighting explosion
320 Mod_FindNonSolidLocation(pos, cl.worldmodel);
321 CL_ParticleExplosion (pos, false);
322 // CL_BlastParticles (pos, 120, 120);
323 color[0] = MSG_ReadByte() * (1.0 / 255.0);
324 color[1] = MSG_ReadByte() * (1.0 / 255.0);
325 color[2] = MSG_ReadByte() * (1.0 / 255.0);
326 CL_AllocDlight (NULL, pos, 350, color[0], color[1], color[2], 700, 0.5);
327 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
330 case TE_TAREXPLOSION: // tarbaby explosion
332 Mod_FindNonSolidLocation(pos, cl.worldmodel);
333 CL_BlobExplosion (pos);
334 // CL_BlastParticles (pos, 120, 120);
336 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
337 CL_AllocDlight (NULL, pos, 600, 0.8f, 0.4f, 1.0f, 1200, 0.5);
338 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
343 Mod_FindNonSolidLocation(pos, cl.worldmodel);
344 CL_AllocDlight (NULL, pos, 200, 1, 1, 1, 1000, 0.2);
349 Mod_FindNonSolidLocation(pos, cl.worldmodel);
350 radius = MSG_ReadByte() * 8;
351 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
352 color[0] = MSG_ReadByte() * (1.0 / 255.0);
353 color[1] = MSG_ReadByte() * (1.0 / 255.0);
354 color[2] = MSG_ReadByte() * (1.0 / 255.0);
355 CL_AllocDlight (NULL, pos, radius, color[0], color[1], color[2], radius / velspeed, velspeed);
361 count = MSG_ReadByte();
362 CL_Flames(pos, dir, count);
365 case TE_LIGHTNING1: // lightning bolts
367 cl_model_bolt = Mod_ForName("progs/bolt.mdl", true, false, false);
368 CL_ParseBeam (cl_model_bolt);
371 case TE_LIGHTNING2: // lightning bolts
373 cl_model_bolt2 = Mod_ForName("progs/bolt2.mdl", true, false, false);
374 CL_ParseBeam (cl_model_bolt2);
377 case TE_LIGHTNING3: // lightning bolts
379 cl_model_bolt3 = Mod_ForName("progs/bolt3.mdl", true, false, false);
380 CL_ParseBeam (cl_model_bolt3);
384 case TE_BEAM: // grappling hook beam
386 cl_model_beam = Mod_ForName("progs/beam.mdl", true, false, false);
387 CL_ParseBeam (cl_model_beam);
391 // LordHavoc: for compatibility with the Nehahra movie...
392 case TE_LIGHTNING4NEH:
393 CL_ParseBeam (Mod_ForName(MSG_ReadString(), true, false, false));
397 pos[0] = MSG_ReadCoord ();
398 pos[1] = MSG_ReadCoord ();
399 pos[2] = MSG_ReadCoord ();
404 pos[0] = MSG_ReadCoord ();
405 pos[1] = MSG_ReadCoord ();
406 pos[2] = MSG_ReadCoord ();
407 CL_TeleportSplash (pos);
410 case TE_EXPLOSION2: // color mapped explosion
412 Mod_FindNonSolidLocation(pos, cl.worldmodel);
413 colorStart = MSG_ReadByte ();
414 colorLength = MSG_ReadByte ();
415 CL_ParticleExplosion2 (pos, colorStart, colorLength);
416 // CL_BlastParticles (pos, 80, 80);
417 tempcolor = (byte *)&d_8to24table[(rand()%colorLength) + colorStart];
418 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);
419 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
423 Host_Error ("CL_ParseTEnt: bad type %d", type);
433 entity_t *CL_NewTempEntity (void)
437 if (r_refdef.numentities >= MAX_VISEDICTS)
439 if (num_temp_entities >= MAX_TEMP_ENTITIES)
441 ent = &cl_temp_entities[num_temp_entities++];
442 memset (ent, 0, sizeof(*ent));
443 r_refdef.entities[r_refdef.numentities++] = &ent->render;
445 ent->render.colormap = -1; // no special coloring
446 ent->render.scale = 1;
447 ent->render.alpha = 1;
457 void CL_UpdateTEnts (void)
467 num_temp_entities = 0;
470 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
472 if (!b->model || b->endtime < cl.time)
475 // if coming from the player, update the start position
476 if (b->entity == cl.viewentity)
477 VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
479 // calculate pitch and yaw
480 VectorSubtract (b->end, b->start, dist);
482 if (dist[1] == 0 && dist[0] == 0)
492 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
496 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
497 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
502 // add new entities for the lightning
503 VectorCopy (b->start, org);
504 d = VectorNormalizeLength(dist);
507 ent = CL_NewTempEntity ();
510 VectorCopy (org, ent->render.origin);
511 ent->render.model = b->model;
512 ent->render.effects = EF_FULLBRIGHT;
513 ent->render.angles[0] = pitch;
514 ent->render.angles[1] = yaw;
515 ent->render.angles[2] = rand()%360;
516 VectorMA(org, 30, dist, org);