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", false);
49 cl_sfx_knighthit = S_PrecacheSound ("hknight/hit.wav", false);
50 cl_sfx_tink1 = S_PrecacheSound ("weapons/tink1.wav", false);
51 cl_sfx_ric1 = S_PrecacheSound ("weapons/ric1.wav", false);
52 cl_sfx_ric2 = S_PrecacheSound ("weapons/ric2.wav", false);
53 cl_sfx_ric3 = S_PrecacheSound ("weapons/ric3.wav", false);
54 cl_sfx_r_exp3 = S_PrecacheSound ("weapons/r_exp3.wav", false);
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);
142 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
147 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
149 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
151 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
154 case TE_SPIKEQUAD: // quad spike hitting wall
156 Mod_FindNonSolidLocation(pos, cl.worldmodel);
157 // LordHavoc: changed to spark shower
158 CL_SparkShower(pos, vec3_origin, 15);
159 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
160 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
162 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
167 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
169 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
171 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
174 case TE_SUPERSPIKE: // super spike hitting wall
176 Mod_FindNonSolidLocation(pos, cl.worldmodel);
177 // LordHavoc: changed to dust shower
178 CL_SparkShower(pos, vec3_origin, 30);
180 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
185 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
187 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
189 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
192 case TE_SUPERSPIKEQUAD: // quad super spike hitting wall
194 Mod_FindNonSolidLocation(pos, cl.worldmodel);
195 // LordHavoc: changed to dust shower
196 CL_SparkShower(pos, vec3_origin, 30);
197 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
199 S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
204 S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
206 S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
208 S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
211 // LordHavoc: added for improved blood splatters
212 case TE_BLOOD: // blood puff
214 dir[0] = MSG_ReadChar ();
215 dir[1] = MSG_ReadChar ();
216 dir[2] = MSG_ReadChar ();
217 count = MSG_ReadByte (); // amount of particles
218 CL_BloodPuff(pos, dir, count);
220 case TE_BLOOD2: // blood puff
222 CL_BloodPuff(pos, vec3_origin, 10);
224 case TE_SPARK: // spark shower
226 dir[0] = MSG_ReadChar ();
227 dir[1] = MSG_ReadChar ();
228 dir[2] = MSG_ReadChar ();
229 count = MSG_ReadByte (); // amount of particles
230 Mod_FindNonSolidLocation(pos, cl.worldmodel);
231 CL_SparkShower(pos, dir, count);
235 Mod_FindNonSolidLocation(pos, cl.worldmodel);
236 CL_AllocDlight (NULL, pos, 200, 1, 1, 1, 1000, 0.2);
239 // LordHavoc: added for improved gore
240 case TE_BLOODSHOWER: // vaporized body
241 MSG_ReadVector(pos); // mins
242 MSG_ReadVector(pos2); // maxs
243 velspeed = MSG_ReadCoord (); // speed
244 count = MSG_ReadShort (); // number of particles
245 CL_BloodShower(pos, pos2, velspeed, count);
247 case TE_PARTICLECUBE: // general purpose particle effect
248 MSG_ReadVector(pos); // mins
249 MSG_ReadVector(pos2); // maxs
250 MSG_ReadVector(dir); // dir
251 count = MSG_ReadShort (); // number of particles
252 colorStart = MSG_ReadByte (); // color
253 colorLength = MSG_ReadByte (); // gravity (1 or 0)
254 velspeed = MSG_ReadCoord (); // randomvel
255 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
258 case TE_PARTICLERAIN: // 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, 0);
267 case TE_PARTICLESNOW: // general purpose particle effect
268 MSG_ReadVector(pos); // mins
269 MSG_ReadVector(pos2); // maxs
270 MSG_ReadVector(dir); // dir
271 count = MSG_ReadShort (); // number of particles
272 colorStart = MSG_ReadByte (); // color
273 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
276 case TE_GUNSHOT: // bullet hitting wall
278 Mod_FindNonSolidLocation(pos, cl.worldmodel);
279 // LordHavoc: changed to dust shower
280 CL_SparkShower(pos, vec3_origin, 15);
283 case TE_GUNSHOTQUAD: // quad bullet hitting wall
285 Mod_FindNonSolidLocation(pos, cl.worldmodel);
286 CL_SparkShower(pos, vec3_origin, 15);
287 CL_AllocDlight (NULL, pos, 200, 0.1f, 0.1f, 1.0f, 1000, 0.2);
290 case TE_EXPLOSION: // rocket explosion
292 Mod_FindNonSolidLocation(pos, cl.worldmodel);
293 CL_ParticleExplosion (pos, false);
294 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
295 CL_AllocDlight (NULL, pos, 350, 1.25f, 1.0f, 0.5f, 700, 0.5);
296 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
299 case TE_EXPLOSIONQUAD: // quad rocket explosion
301 Mod_FindNonSolidLocation(pos, cl.worldmodel);
302 CL_ParticleExplosion (pos, false);
303 CL_AllocDlight (NULL, pos, 600, 0.5f, 0.4f, 1.0f, 1200, 0.5);
304 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
307 case TE_EXPLOSION3: // Nehahra movie colored lighting explosion
309 Mod_FindNonSolidLocation(pos, cl.worldmodel);
310 CL_ParticleExplosion (pos, false);
311 CL_AllocDlight (NULL, pos, 350, MSG_ReadCoord(), MSG_ReadCoord(), MSG_ReadCoord(), 700, 0.5);
312 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
315 case TE_EXPLOSIONRGB: // colored lighting explosion
317 Mod_FindNonSolidLocation(pos, cl.worldmodel);
318 CL_ParticleExplosion (pos, false);
319 color[0] = MSG_ReadByte() * (1.0 / 255.0);
320 color[1] = MSG_ReadByte() * (1.0 / 255.0);
321 color[2] = MSG_ReadByte() * (1.0 / 255.0);
322 CL_AllocDlight (NULL, pos, 350, color[0], color[1], color[2], 700, 0.5);
323 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
326 case TE_TAREXPLOSION: // tarbaby explosion
328 Mod_FindNonSolidLocation(pos, cl.worldmodel);
329 CL_BlobExplosion (pos);
331 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
332 CL_AllocDlight (NULL, pos, 600, 0.8f, 0.4f, 1.0f, 1200, 0.5);
333 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
338 Mod_FindNonSolidLocation(pos, cl.worldmodel);
339 CL_AllocDlight (NULL, pos, 200, 1, 1, 1, 1000, 0.2);
344 Mod_FindNonSolidLocation(pos, cl.worldmodel);
345 radius = MSG_ReadByte() * 8;
346 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
347 color[0] = MSG_ReadByte() * (1.0 / 255.0);
348 color[1] = MSG_ReadByte() * (1.0 / 255.0);
349 color[2] = MSG_ReadByte() * (1.0 / 255.0);
350 CL_AllocDlight (NULL, pos, radius, color[0], color[1], color[2], radius / velspeed, velspeed);
356 count = MSG_ReadByte();
357 CL_Flames(pos, dir, count);
360 case TE_LIGHTNING1: // lightning bolts
362 cl_model_bolt = Mod_ForName("progs/bolt.mdl", true, false, false);
363 CL_ParseBeam (cl_model_bolt);
366 case TE_LIGHTNING2: // lightning bolts
368 cl_model_bolt2 = Mod_ForName("progs/bolt2.mdl", true, false, false);
369 CL_ParseBeam (cl_model_bolt2);
372 case TE_LIGHTNING3: // lightning bolts
374 cl_model_bolt3 = Mod_ForName("progs/bolt3.mdl", true, false, false);
375 CL_ParseBeam (cl_model_bolt3);
379 case TE_BEAM: // grappling hook beam
381 cl_model_beam = Mod_ForName("progs/beam.mdl", true, false, false);
382 CL_ParseBeam (cl_model_beam);
386 // LordHavoc: for compatibility with the Nehahra movie...
387 case TE_LIGHTNING4NEH:
388 CL_ParseBeam (Mod_ForName(MSG_ReadString(), true, false, false));
392 pos[0] = MSG_ReadCoord ();
393 pos[1] = MSG_ReadCoord ();
394 pos[2] = MSG_ReadCoord ();
399 pos[0] = MSG_ReadCoord ();
400 pos[1] = MSG_ReadCoord ();
401 pos[2] = MSG_ReadCoord ();
402 CL_AllocDlight (NULL, pos, 1000, 1.25f, 1.25f, 1.25f, 3000, 99.0f);
403 // CL_TeleportSplash (pos);
406 case TE_EXPLOSION2: // color mapped explosion
408 Mod_FindNonSolidLocation(pos, cl.worldmodel);
409 colorStart = MSG_ReadByte ();
410 colorLength = MSG_ReadByte ();
411 CL_ParticleExplosion2 (pos, colorStart, colorLength);
412 tempcolor = (qbyte *)&d_8to24table[(rand()%colorLength) + colorStart];
413 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);
414 S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
418 Host_Error ("CL_ParseTEnt: bad type %d", type);
428 entity_t *CL_NewTempEntity (void)
432 if (r_refdef.numentities >= MAX_VISEDICTS)
434 if (num_temp_entities >= MAX_TEMP_ENTITIES)
436 ent = &cl_temp_entities[num_temp_entities++];
437 memset (ent, 0, sizeof(*ent));
438 r_refdef.entities[r_refdef.numentities++] = &ent->render;
440 ent->render.colormap = -1; // no special coloring
441 ent->render.scale = 1;
442 ent->render.alpha = 1;
452 void CL_UpdateTEnts (void)
462 num_temp_entities = 0;
465 for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
467 if (!b->model || b->endtime < cl.time)
470 // if coming from the player, update the start position
471 if (b->entity == cl.viewentity)
472 VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
474 // calculate pitch and yaw
475 VectorSubtract (b->end, b->start, dist);
477 if (dist[1] == 0 && dist[0] == 0)
487 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
491 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
492 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
497 // add new entities for the lightning
498 VectorCopy (b->start, org);
499 d = VectorNormalizeLength(dist);
502 ent = CL_NewTempEntity ();
505 VectorCopy (org, ent->render.origin);
506 ent->render.model = b->model;
507 ent->render.effects = EF_FULLBRIGHT;
508 ent->render.angles[0] = pitch;
509 ent->render.angles[1] = yaw;
510 ent->render.angles[2] = rand()%360;
511 VectorMA(org, 30, dist, org);