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 Mod_FindNonSolidLocation(pos, cl.worldmodel);
125 CL_RunParticleEffect (pos, vec3_origin, 20, 30);
126 S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
129 case TE_KNIGHTSPIKE: // spike hitting wall
131 Mod_FindNonSolidLocation(pos, cl.worldmodel);
132 CL_RunParticleEffect (pos, vec3_origin, 226, 20);
133 S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
136 case TE_SPIKE: // spike hitting wall
138 Mod_FindNonSolidLocation(pos, cl.worldmodel);
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 Mod_FindNonSolidLocation(pos, cl.worldmodel);
158 // LordHavoc: changed to spark shower
159 CL_SparkShower(pos, vec3_origin, 15);
160 //CL_RunParticleEffect (pos, vec3_origin, 0, 10);
161 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
162 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
164 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
169 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
171 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
173 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
176 case TE_SUPERSPIKE: // super spike hitting wall
178 Mod_FindNonSolidLocation(pos, cl.worldmodel);
179 // LordHavoc: changed to dust shower
180 CL_SparkShower(pos, vec3_origin, 30);
181 //CL_RunParticleEffect (pos, vec3_origin, 0, 20);
183 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
188 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
190 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
192 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
195 case TE_SUPERSPIKEQUAD: // quad super spike hitting wall
197 Mod_FindNonSolidLocation(pos, cl.worldmodel);
198 // LordHavoc: changed to dust shower
199 CL_SparkShower(pos, vec3_origin, 30);
200 //CL_RunParticleEffect (pos, vec3_origin, 0, 20);
201 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
203 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
208 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
210 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
212 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
215 // LordHavoc: added for improved blood splatters
216 case TE_BLOOD: // blood puff
218 dir[0] = MSG_ReadChar ();
219 dir[1] = MSG_ReadChar ();
220 dir[2] = MSG_ReadChar ();
221 count = MSG_ReadByte (); // amount of particles
222 CL_BloodPuff(pos, dir, count);
224 case TE_BLOOD2: // blood puff
226 CL_BloodPuff(pos, vec3_origin, 10);
228 case TE_SPARK: // spark shower
230 dir[0] = MSG_ReadChar ();
231 dir[1] = MSG_ReadChar ();
232 dir[2] = MSG_ReadChar ();
233 count = MSG_ReadByte (); // amount of particles
234 Mod_FindNonSolidLocation(pos, cl.worldmodel);
235 CL_SparkShower(pos, dir, count);
239 Mod_FindNonSolidLocation(pos, cl.worldmodel);
240 CL_AllocDlight (NULL, pos, 200, 1, 1, 1, 1000, 0.2);
243 // LordHavoc: added for improved gore
244 case TE_BLOODSHOWER: // vaporized body
245 MSG_ReadVector(pos); // mins
246 MSG_ReadVector(pos2); // maxs
247 velspeed = MSG_ReadCoord (); // speed
248 count = MSG_ReadShort (); // number of particles
249 CL_BloodShower(pos, pos2, velspeed, count);
251 case TE_PARTICLECUBE: // general purpose particle effect
252 MSG_ReadVector(pos); // mins
253 MSG_ReadVector(pos2); // maxs
254 MSG_ReadVector(dir); // dir
255 count = MSG_ReadShort (); // number of particles
256 colorStart = MSG_ReadByte (); // color
257 colorLength = MSG_ReadByte (); // gravity (1 or 0)
258 velspeed = MSG_ReadCoord (); // randomvel
259 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
262 case TE_PARTICLERAIN: // general purpose particle effect
263 MSG_ReadVector(pos); // mins
264 MSG_ReadVector(pos2); // maxs
265 MSG_ReadVector(dir); // dir
266 count = MSG_ReadShort (); // number of particles
267 colorStart = MSG_ReadByte (); // color
268 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
271 case TE_PARTICLESNOW: // general purpose particle effect
272 MSG_ReadVector(pos); // mins
273 MSG_ReadVector(pos2); // maxs
274 MSG_ReadVector(dir); // dir
275 count = MSG_ReadShort (); // number of particles
276 colorStart = MSG_ReadByte (); // color
277 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
280 case TE_GUNSHOT: // bullet hitting wall
282 Mod_FindNonSolidLocation(pos, cl.worldmodel);
283 // LordHavoc: changed to dust shower
284 CL_SparkShower(pos, vec3_origin, 15);
285 //CL_RunParticleEffect (pos, vec3_origin, 0, 20);
288 case TE_GUNSHOTQUAD: // quad bullet hitting wall
290 Mod_FindNonSolidLocation(pos, cl.worldmodel);
291 CL_SparkShower(pos, vec3_origin, 15);
292 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
295 case TE_EXPLOSION: // rocket explosion
297 Mod_FindNonSolidLocation(pos, cl.worldmodel);
298 CL_ParticleExplosion (pos, false);
299 // CL_BlastParticles (pos, 120, 120);
300 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
301 CL_AllocDlight (NULL, pos, 350, 1.25f, 1.0f, 0.5f, 700, 0.5);
302 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
305 case TE_EXPLOSIONQUAD: // quad rocket explosion
307 Mod_FindNonSolidLocation(pos, cl.worldmodel);
308 CL_ParticleExplosion (pos, false);
309 // CL_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 Mod_FindNonSolidLocation(pos, cl.worldmodel);
318 CL_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 Mod_FindNonSolidLocation(pos, cl.worldmodel);
327 CL_ParticleExplosion (pos, false);
328 // CL_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 Mod_FindNonSolidLocation(pos, cl.worldmodel);
336 CL_ParticleExplosion (pos, false);
337 // CL_BlastParticles (pos, 120, 120);
338 color[0] = MSG_ReadByte() * (1.0 / 255.0);
339 color[1] = MSG_ReadByte() * (1.0 / 255.0);
340 color[2] = MSG_ReadByte() * (1.0 / 255.0);
341 CL_AllocDlight (NULL, pos, 350, color[0], color[1], color[2], 700, 0.5);
342 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
345 case TE_TAREXPLOSION: // tarbaby explosion
347 Mod_FindNonSolidLocation(pos, cl.worldmodel);
348 CL_BlobExplosion (pos);
349 // CL_BlastParticles (pos, 120, 120);
351 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
352 CL_AllocDlight (NULL, pos, 600, 0.8f, 0.4f, 1.0f, 1200, 0.5);
353 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
358 Mod_FindNonSolidLocation(pos, cl.worldmodel);
359 CL_AllocDlight (NULL, pos, 200, 1, 1, 1, 1000, 0.2);
364 Mod_FindNonSolidLocation(pos, cl.worldmodel);
365 radius = MSG_ReadByte() * 8;
366 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
367 color[0] = MSG_ReadByte() * (1.0 / 255.0);
368 color[1] = MSG_ReadByte() * (1.0 / 255.0);
369 color[2] = MSG_ReadByte() * (1.0 / 255.0);
370 CL_AllocDlight (NULL, pos, radius, color[0], color[1], color[2], radius / velspeed, velspeed);
376 count = MSG_ReadByte();
377 CL_Flames(pos, dir, count);
380 case TE_LIGHTNING1: // lightning bolts
382 cl_model_bolt = Mod_ForName("progs/bolt.mdl", true, false, false);
383 CL_ParseBeam (cl_model_bolt);
386 case TE_LIGHTNING2: // lightning bolts
388 cl_model_bolt2 = Mod_ForName("progs/bolt2.mdl", true, false, false);
389 CL_ParseBeam (cl_model_bolt2);
392 case TE_LIGHTNING3: // lightning bolts
394 cl_model_bolt3 = Mod_ForName("progs/bolt3.mdl", true, false, false);
395 CL_ParseBeam (cl_model_bolt3);
399 case TE_BEAM: // grappling hook beam
401 cl_model_beam = Mod_ForName("progs/beam.mdl", true, false, false);
402 CL_ParseBeam (cl_model_beam);
406 // LordHavoc: for compatibility with the Nehahra movie...
407 case TE_LIGHTNING4NEH:
408 CL_ParseBeam (Mod_ForName(MSG_ReadString(), true, false, false));
412 pos[0] = MSG_ReadCoord ();
413 pos[1] = MSG_ReadCoord ();
414 pos[2] = MSG_ReadCoord ();
419 pos[0] = MSG_ReadCoord ();
420 pos[1] = MSG_ReadCoord ();
421 pos[2] = MSG_ReadCoord ();
422 CL_TeleportSplash (pos);
425 case TE_EXPLOSION2: // color mapped explosion
427 Mod_FindNonSolidLocation(pos, cl.worldmodel);
428 colorStart = MSG_ReadByte ();
429 colorLength = MSG_ReadByte ();
430 CL_ParticleExplosion2 (pos, colorStart, colorLength);
431 // CL_BlastParticles (pos, 80, 80);
432 tempcolor = (qbyte *)&d_8to24table[(rand()%colorLength) + colorStart];
433 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);
434 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
438 Host_Error ("CL_ParseTEnt: bad type %d", type);
448 entity_t *CL_NewTempEntity (void)
452 if (r_refdef.numentities >= MAX_VISEDICTS)
454 if (num_temp_entities >= MAX_TEMP_ENTITIES)
456 ent = &cl_temp_entities[num_temp_entities++];
457 memset (ent, 0, sizeof(*ent));
458 r_refdef.entities[r_refdef.numentities++] = &ent->render;
460 ent->render.colormap = -1; // no special coloring
461 ent->render.scale = 1;
462 ent->render.alpha = 1;
472 void CL_UpdateTEnts (void)
482 num_temp_entities = 0;
485 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
487 if (!b->model || b->endtime < cl.time)
490 // if coming from the player, update the start position
491 if (b->entity == cl.viewentity)
492 VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
494 // calculate pitch and yaw
495 VectorSubtract (b->end, b->start, dist);
497 if (dist[1] == 0 && dist[0] == 0)
507 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
511 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
512 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
517 // add new entities for the lightning
518 VectorCopy (b->start, org);
519 d = VectorNormalizeLength(dist);
522 ent = CL_NewTempEntity ();
525 VectorCopy (org, ent->render.origin);
526 ent->render.model = b->model;
527 ent->render.effects = EF_FULLBRIGHT;
528 ent->render.angles[0] = pitch;
529 ent->render.angles[1] = yaw;
530 ent->render.angles[2] = rand()%360;
531 VectorMA(org, 30, dist, org);