]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_tent.c
a little cleanup, and eliminated a lightstyle buffer overflow
[xonotic/darkplaces.git] / cl_tent.c
index 573dc59383fda3c126fbffbf65e88ad0ac928229..518b1ef417c1d58655a8375976e3bc9ad22a1dd3 100644 (file)
--- a/cl_tent.c
+++ b/cl_tent.c
@@ -21,6 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
+#define MSG_ReadVector(v) {(v)[0] = MSG_ReadCoord();(v)[1] = MSG_ReadCoord();(v)[2] = MSG_ReadCoord();}
+
+cvar_t r_glowinglightning = {"r_glowinglightning", "1", true};
+
 int                    num_temp_entities;
 entity_t       cl_temp_entities[MAX_TEMP_ENTITIES];
 beam_t         cl_beams[MAX_BEAMS];
@@ -40,6 +44,7 @@ CL_ParseTEnt
 */
 void CL_InitTEnts (void)
 {
+       Cvar_RegisterVariable(&r_glowinglightning);
        cl_sfx_wizhit = S_PrecacheSound ("wizard/hit.wav");
        cl_sfx_knighthit = S_PrecacheSound ("hknight/hit.wav");
        cl_sfx_tink1 = S_PrecacheSound ("weapons/tink1.wav");
@@ -62,14 +67,8 @@ void CL_ParseBeam (model_t *m)
        int             i;
        
        ent = MSG_ReadShort ();
-       
-       start[0] = MSG_ReadCoord ();
-       start[1] = MSG_ReadCoord ();
-       start[2] = MSG_ReadCoord ();
-       
-       end[0] = MSG_ReadCoord ();
-       end[1] = MSG_ReadCoord ();
-       end[2] = MSG_ReadCoord ();
+       MSG_ReadVector(start);
+       MSG_ReadVector(end);
 
 // override any beam with the same entity
        for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
@@ -99,10 +98,26 @@ void CL_ParseBeam (model_t *m)
        Con_Printf ("beam list overflow!\n");   
 }
 
+//void R_BlastParticles(vec3_t org, vec_t radius, vec_t power);
 void R_BloodShower (vec3_t mins, vec3_t maxs, float velspeed, int count);
 void R_ParticleCube (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int gravity, int randomvel);
 void R_ParticleRain (vec3_t mins, vec3_t maxs, vec3_t dir, int count, int colorbase, int type);
 
+// attempts to find the nearest non-solid location, used for explosions mainly
+void FindNonSolidLocation(vec3_t pos)
+{
+       if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
+       pos[0]-=1;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
+       pos[0]+=2;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
+       pos[0]-=1;
+       pos[1]-=1;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
+       pos[1]+=2;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
+       pos[1]-=1;
+       pos[2]-=1;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
+       pos[2]+=2;if (SV_HullPointContents (cl.worldmodel->hulls, 0, pos) != CONTENTS_SOLID) return;
+       pos[2]-=1;
+}
+
 /*
 =================
 CL_ParseTEnt
@@ -124,27 +139,21 @@ void CL_ParseTEnt (void)
        switch (type)
        {
        case TE_WIZSPIKE:                       // spike hitting wall
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
                R_RunParticleEffect (pos, vec3_origin, 20, 30);
                S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
                break;
                
        case TE_KNIGHTSPIKE:                    // spike hitting wall
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
                R_RunParticleEffect (pos, vec3_origin, 226, 20);
                S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
                break;
                
        case TE_SPIKE:                  // spike hitting wall
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
                // LordHavoc: changed to spark shower
-               R_SparkShower(pos, vec3_origin, 15, 0);
+               R_SparkShower(pos, vec3_origin, 15);
                //R_RunParticleEffect (pos, vec3_origin, 0, 10);
                if ( rand() % 5 )
                        S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
@@ -160,11 +169,9 @@ void CL_ParseTEnt (void)
                }
                break;
        case TE_SPIKEQUAD:                      // quad spike hitting wall
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
                // LordHavoc: changed to spark shower
-               R_SparkShower(pos, vec3_origin, 15, 0);
+               R_SparkShower(pos, vec3_origin, 15);
                //R_RunParticleEffect (pos, vec3_origin, 0, 10);
                dl = CL_AllocDlight (0);
                VectorCopy (pos, dl->origin);
@@ -187,11 +194,9 @@ void CL_ParseTEnt (void)
                }
                break;
        case TE_SUPERSPIKE:                     // super spike hitting wall
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
                // LordHavoc: changed to dust shower
-               R_SparkShower(pos, vec3_origin, 30, 0);
+               R_SparkShower(pos, vec3_origin, 30);
                //R_RunParticleEffect (pos, vec3_origin, 0, 20);
                if ( rand() % 5 )
                        S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
@@ -207,11 +212,9 @@ void CL_ParseTEnt (void)
                }
                break;
        case TE_SUPERSPIKEQUAD:                 // quad super spike hitting wall
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
                // LordHavoc: changed to dust shower
-               R_SparkShower(pos, vec3_origin, 30, 0);
+               R_SparkShower(pos, vec3_origin, 30);
                //R_RunParticleEffect (pos, vec3_origin, 0, 20);
                dl = CL_AllocDlight (0);
                VectorCopy (pos, dl->origin);
@@ -234,47 +237,37 @@ void CL_ParseTEnt (void)
                break;
                // LordHavoc: added for improved blood splatters
        case TE_BLOOD:  // blood puff
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
                dir[0] = MSG_ReadChar ();
                dir[1] = MSG_ReadChar ();
                dir[2] = MSG_ReadChar ();
                count = MSG_ReadByte (); // amount of particles
-               R_SparkShower(pos, dir, count, 1);
+               R_BloodPuff(pos);
+               break;
+       case TE_BLOOD2: // blood puff
+               MSG_ReadVector(pos);
+               R_BloodPuff(pos);
                break;
        case TE_SPARK:  // spark shower
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
                dir[0] = MSG_ReadChar ();
                dir[1] = MSG_ReadChar ();
                dir[2] = MSG_ReadChar ();
                count = MSG_ReadByte (); // amount of particles
-               R_SparkShower(pos, dir, count, 0);
+               R_SparkShower(pos, dir, count);
                break;
                // LordHavoc: added for improved gore
        case TE_BLOODSHOWER:    // vaporized body
-               pos[0] = MSG_ReadCoord (); // mins
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
-               dir[0] = MSG_ReadCoord (); // maxs
-               dir[1] = MSG_ReadCoord ();
-               dir[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos); // mins
+               MSG_ReadVector(pos2); // maxs
                velspeed = MSG_ReadCoord (); // speed
                count = MSG_ReadShort (); // number of particles
-               R_BloodShower(pos, dir, velspeed, count);
+               R_BloodShower(pos, pos2, velspeed, count);
                break;
        case TE_PARTICLECUBE:   // general purpose particle effect
-               pos[0] = MSG_ReadCoord (); // mins
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
-               pos2[0] = MSG_ReadCoord (); // maxs
-               pos2[1] = MSG_ReadCoord ();
-               pos2[2] = MSG_ReadCoord ();
-               dir[0] = MSG_ReadCoord (); // dir
-               dir[1] = MSG_ReadCoord ();
-               dir[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos); // mins
+               MSG_ReadVector(pos2); // maxs
+               MSG_ReadVector(dir); // dir
                count = MSG_ReadShort (); // number of particles
                colorStart = MSG_ReadByte (); // color
                colorLength = MSG_ReadByte (); // gravity (1 or 0)
@@ -283,49 +276,33 @@ void CL_ParseTEnt (void)
                break;
 
        case TE_PARTICLERAIN:   // general purpose particle effect
-               pos[0] = MSG_ReadCoord (); // mins
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
-               pos2[0] = MSG_ReadCoord (); // maxs
-               pos2[1] = MSG_ReadCoord ();
-               pos2[2] = MSG_ReadCoord ();
-               dir[0] = MSG_ReadCoord (); // dir
-               dir[1] = MSG_ReadCoord ();
-               dir[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos); // mins
+               MSG_ReadVector(pos2); // maxs
+               MSG_ReadVector(dir); // dir
                count = MSG_ReadShort (); // number of particles
                colorStart = MSG_ReadByte (); // color
                R_ParticleRain(pos, pos2, dir, count, colorStart, 0);
                break;
 
        case TE_PARTICLESNOW:   // general purpose particle effect
-               pos[0] = MSG_ReadCoord (); // mins
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
-               pos2[0] = MSG_ReadCoord (); // maxs
-               pos2[1] = MSG_ReadCoord ();
-               pos2[2] = MSG_ReadCoord ();
-               dir[0] = MSG_ReadCoord (); // dir
-               dir[1] = MSG_ReadCoord ();
-               dir[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos); // mins
+               MSG_ReadVector(pos2); // maxs
+               MSG_ReadVector(dir); // dir
                count = MSG_ReadShort (); // number of particles
                colorStart = MSG_ReadByte (); // color
                R_ParticleRain(pos, pos2, dir, count, colorStart, 1);
                break;
 
        case TE_GUNSHOT:                        // bullet hitting wall
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
                // LordHavoc: changed to dust shower
-               R_SparkShower(pos, vec3_origin, 15, 0);
+               R_SparkShower(pos, vec3_origin, 15);
                //R_RunParticleEffect (pos, vec3_origin, 0, 20);
                break;
 
        case TE_GUNSHOTQUAD:                    // quad bullet hitting wall
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
-               R_SparkShower(pos, vec3_origin, 15, 0);
+               MSG_ReadVector(pos);
+               R_SparkShower(pos, vec3_origin, 15);
                dl = CL_AllocDlight (0);
                VectorCopy (pos, dl->origin);
                dl->radius = 200;
@@ -335,10 +312,10 @@ void CL_ParseTEnt (void)
                break;
 
        case TE_EXPLOSION:                      // rocket explosion
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
+               FindNonSolidLocation(pos);
                R_ParticleExplosion (pos, false);
+//             R_BlastParticles (pos, 120, 120);
                dl = CL_AllocDlight (0);
                VectorCopy (pos, dl->origin);
                dl->radius = 350;
@@ -349,10 +326,10 @@ void CL_ParseTEnt (void)
                break;
 
        case TE_EXPLOSIONQUAD:                  // quad rocket explosion
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
+               FindNonSolidLocation(pos);
                R_ParticleExplosion (pos, false);
+//             R_BlastParticles (pos, 120, 480);
                dl = CL_AllocDlight (0);
                VectorCopy (pos, dl->origin);
                dl->radius = 600;
@@ -364,9 +341,8 @@ void CL_ParseTEnt (void)
 
                /*
        case TE_SMOKEEXPLOSION:                 // rocket explosion with a cloud of smoke
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
+               FindNonSolidLocation(pos);
                R_ParticleExplosion (pos, true);
                dl = CL_AllocDlight (0);
                VectorCopy (pos, dl->origin);
@@ -379,10 +355,10 @@ void CL_ParseTEnt (void)
                */
 
        case TE_EXPLOSION3:                             // Nehahra movie colored lighting explosion
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
+               FindNonSolidLocation(pos);
                R_ParticleExplosion (pos, false);
+//             R_BlastParticles (pos, 120, 120);
                dl = CL_AllocDlight (0);
                VectorCopy (pos, dl->origin);
                dl->radius = 350;
@@ -393,10 +369,10 @@ void CL_ParseTEnt (void)
                break;
 
        case TE_EXPLOSIONRGB:                   // colored lighting explosion
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
+               FindNonSolidLocation(pos);
                R_ParticleExplosion (pos, false);
+//             R_BlastParticles (pos, 120, 120);
                dl = CL_AllocDlight (0);
                VectorCopy (pos, dl->origin);
                dl->radius = 350;
@@ -407,11 +383,18 @@ void CL_ParseTEnt (void)
                break;
 
        case TE_TAREXPLOSION:                   // tarbaby explosion
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
+               FindNonSolidLocation(pos);
                R_BlobExplosion (pos);
+//             R_BlastParticles (pos, 120, 120);
 
+               S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
+               dl = CL_AllocDlight (0);
+               VectorCopy (pos, dl->origin);
+               dl->radius = 600;
+               dl->die = cl.time + 0.5;
+               dl->decay = 1200;
+               dl->color[0] = 0.8;dl->color[1] = 0.4;dl->color[2] = 1.0;
                S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
                break;
 
@@ -433,7 +416,7 @@ void CL_ParseTEnt (void)
                break;
 // PGM 01/21/97
 
-// LordHavoc: ONLY for compatibility with the Nehahra movie... hack hack hack
+// LordHavoc: for compatibility with the Nehahra movie...
        case TE_LIGHTNING4NEH:
                CL_ParseBeam (Mod_ForName(MSG_ReadString(), true));
                break;
@@ -453,19 +436,19 @@ void CL_ParseTEnt (void)
                break;
                
        case TE_EXPLOSION2:                             // color mapped explosion
-               pos[0] = MSG_ReadCoord ();
-               pos[1] = MSG_ReadCoord ();
-               pos[2] = MSG_ReadCoord ();
+               MSG_ReadVector(pos);
+               FindNonSolidLocation(pos);
                colorStart = MSG_ReadByte ();
                colorLength = MSG_ReadByte ();
                R_ParticleExplosion2 (pos, colorStart, colorLength);
+//             R_BlastParticles (pos, 80, 80);
                dl = CL_AllocDlight (0);
                VectorCopy (pos, dl->origin);
                dl->radius = 350;
                dl->die = cl.time + 0.5;
                dl->decay = 700;
-               tempcolor = (byte *)&d_8to24table[colorStart+(colorLength >> 1)];
-               dl->color[0] = tempcolor[0];dl->color[1] = tempcolor[1];dl->color[2] = tempcolor[2];
+               tempcolor = (byte *)&d_8to24table[(rand()%colorLength) + colorStart];
+               dl->color[0] = tempcolor[0] * (1.0f / 255.0f);dl->color[1] = tempcolor[1] * (1.0f / 255.0f);dl->color[2] = tempcolor[2] * (1.0f / 255.0f);
                S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
                break;
                
@@ -494,7 +477,7 @@ entity_t *CL_NewTempEntity (void)
        cl_visedicts[cl_numvisedicts] = ent;
        cl_numvisedicts++;
 
-       ent->colormap = vid.colormap;
+       ent->colormap = -1; // no special coloring
        ent->scale = 1;
        ent->alpha = 1;
        ent->colormod[0] = ent->colormod[1] = ent->colormod[2] = 1;
@@ -570,14 +553,16 @@ void CL_UpdateTEnts (void)
                        ent->angles[1] = yaw;
                        ent->angles[2] = rand()%360;
 
-                       dl = CL_AllocDlight (0);
-                       VectorCopy (ent->origin,  dl->origin);
-                       dl->radius = 100 + (rand()&31);
-                       dl->die = cl.time + 0.001;
-                       dl->color[0] = 1;dl->color[1] = 1;dl->color[2] = 1;
+                       if (r_glowinglightning.value)
+                       {
+                               dl = CL_AllocDlight (0);
+                               VectorCopy (ent->origin,  dl->origin);
+                               dl->radius = 100 + (rand()&31);
+                               dl->die = cl.time + 0.001;
+                               dl->color[0] = 1;dl->color[1] = 1;dl->color[2] = 1;
+                       }
 
-                       for (i=0 ; i<3 ; i++)
-                               org[i] += dist[i]*30;
+                       VectorMA(org, 30, dist, org);
                        d -= 30;
                }
        }