]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - view.c
renamed cl_deathtilt to v_deathtilt to match FTE, fuhquake and ezquake engines
[xonotic/darkplaces.git] / view.c
diff --git a/view.c b/view.c
index 775a02c438b19b05b2054b8a72f7a5b8e0cf9089..589f8f15ff5f673e0321ff267a54056a9e904bff 100644 (file)
--- a/view.c
+++ b/view.c
@@ -56,6 +56,16 @@ cvar_t       crosshair = {CVAR_SAVE, "crosshair", "0"};
 cvar_t v_centermove = {0, "v_centermove", "0.15"};
 cvar_t v_centerspeed = {0, "v_centerspeed","500"};
 
+cvar_t cl_stairsmoothspeed = {CVAR_SAVE, "cl_stairsmoothspeed", "160"};
+
+cvar_t chase_back = {CVAR_SAVE, "chase_back", "48"};
+cvar_t chase_up = {CVAR_SAVE, "chase_up", "24"};
+cvar_t chase_active = {CVAR_SAVE, "chase_active", "0"};
+// GAME_GOODVSBAD2
+cvar_t chase_stevie = {0, "chase_stevie", "0"};
+
+cvar_t v_deathtilt = {0, "v_deathtilt", "1"};
+
 float  v_dmg_time, v_dmg_roll, v_dmg_pitch;
 
 
@@ -122,7 +132,7 @@ Drifting is enabled when the center view key is hit, mlook is released and
 lookspring is non 0, or when
 ===============
 */
-static void V_DriftPitch (void)
+void V_DriftPitch (void)
 {
        float           delta, move;
 
@@ -196,7 +206,7 @@ V_ParseDamage
 */
 void V_ParseDamage (void)
 {
-       int i, armor, blood;
+       int armor, blood;
        vec3_t from;
        //vec3_t forward, right;
        vec3_t localfrom;
@@ -206,8 +216,7 @@ void V_ParseDamage (void)
 
        armor = MSG_ReadByte ();
        blood = MSG_ReadByte ();
-       for (i=0 ; i<3 ; i++)
-               from[i] = MSG_ReadCoord ();
+       MSG_ReadVector(from, cl.protocol);
 
        count = blood*0.5 + armor*0.5;
        if (count < 10)
@@ -241,7 +250,7 @@ void V_ParseDamage (void)
        }
 
        // calculate view angle kicks
-       if (cl.viewentity >= 0 && cl.viewentity < MAX_EDICTS && cl_entities[cl.viewentity].state_current.active)
+       if (cl_entities[cl.viewentity].state_current.active)
        {
                ent = &cl_entities[cl.viewentity];
                Matrix4x4_Transform(&ent->render.inversematrix, from, localfrom);
@@ -291,9 +300,9 @@ static void V_BonusFlash_f (void)
 ==============================================================================
 */
 
-#define MAXVIEWMODELS 32
-extern int numviewmodels;
-extern entity_t *viewmodels[MAXVIEWMODELS];
+extern matrix4x4_t viewmodelmatrix;
+
+#include "cl_collision.h"
 
 /*
 ==================
@@ -303,203 +312,246 @@ V_CalcRefdef
 */
 void V_CalcRefdef (void)
 {
-       float r, g, b, a, a2;
-       int j;
+       static float oldz;
        entity_t *ent;
+       float vieworg[3], viewangles[3];
+       trace_t trace;
+       Matrix4x4_CreateIdentity(&viewmodelmatrix);
+       Matrix4x4_CreateIdentity(&r_refdef.viewentitymatrix);
        if (cls.state == ca_connected && cls.signon == SIGNONS)
        {
-               // ent is the player model (visible when out of body)
+               // ent is the view entity (visible when out of body)
                ent = &cl_entities[cl.viewentity];
-               V_DriftPitch();
                if (cl.intermission)
                {
-                       // entity is a fixed camera
-                       VectorCopy(ent->render.origin, r_refdef.vieworg);
-                       VectorCopy(ent->render.angles, r_refdef.viewangles);
-               }
-               else if (chase_active.value)
-               {
-                       // observing entity from third person
-                       VectorCopy(ent->render.origin, r_refdef.vieworg);
-                       VectorCopy(cl.viewangles, r_refdef.viewangles);
-                       Chase_Update();
+                       // entity is a fixed camera, just copy the matrix
+                       Matrix4x4_Copy(&r_refdef.viewentitymatrix, &ent->render.matrix);
+                       Matrix4x4_Copy(&viewmodelmatrix, &ent->render.matrix);
+                       r_refdef.viewentitymatrix.m[2][3] += cl.stats[STAT_VIEWHEIGHT];
+                       viewmodelmatrix.m[2][3] += cl.stats[STAT_VIEWHEIGHT];
                }
                else
                {
-                       // first person view from entity
-                       VectorCopy(ent->render.origin, r_refdef.vieworg);
-                       VectorCopy(cl.viewangles, r_refdef.viewangles);
-                       // angles
-                       if (cl.stats[STAT_HEALTH] <= 0)
-                               r_refdef.viewangles[ROLL] = 80; // dead view angle
-                       VectorAdd(r_refdef.viewangles, cl.punchangle, r_refdef.viewangles);
-                       r_refdef.viewangles[ROLL] += V_CalcRoll(cl.viewangles, cl.velocity);
-                       if (v_dmg_time > 0)
+                       // player can look around, so take the origin from the entity,
+                       // and the angles from the input system
+                       Matrix4x4_OriginFromMatrix(&ent->render.matrix, vieworg);
+                       VectorCopy(cl.viewangles, viewangles);
+
+                       // stair smoothing
+                       //Con_Printf("cl.onground %i oldz %f newz %f\n", cl.onground, oldz, vieworg[2]);
+                       if (cl.onground && oldz < vieworg[2])
                        {
-                               r_refdef.viewangles[ROLL] += v_dmg_time/v_kicktime.value*v_dmg_roll;
-                               r_refdef.viewangles[PITCH] += v_dmg_time/v_kicktime.value*v_dmg_pitch;
-                               v_dmg_time -= cl.frametime;
+                               oldz += (cl.time - cl.oldtime) * cl_stairsmoothspeed.value;
+                               oldz = vieworg[2] = bound(vieworg[2] - 16, oldz, vieworg[2]);
                        }
-                       if (v_idlescale.value)
+                       else if (cl.onground && oldz > vieworg[2])
                        {
-                               r_refdef.viewangles[ROLL] += v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value;
-                               r_refdef.viewangles[PITCH] += v_idlescale.value * sin(cl.time*v_ipitch_cycle.value) * v_ipitch_level.value;
-                               r_refdef.viewangles[YAW] += v_idlescale.value * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value;
+                               oldz -= (cl.time - cl.oldtime) * cl_stairsmoothspeed.value;
+                               oldz = vieworg[2] = bound(vieworg[2], oldz, vieworg[2] + 16);
                        }
-                       // origin
-                       VectorAdd(r_refdef.vieworg, cl.punchvector, r_refdef.vieworg);
-                       r_refdef.vieworg[2] += cl.viewheight;
-                       if (cl_bob.value && cl_bobcycle.value)
+                       else
+                               oldz = vieworg[2];
+
+                       if (chase_active.value)
                        {
-                               double bob, cycle;
-                               // LordHavoc: this code is *weird*, but not replacable (I think it
-                               // should be done in QC on the server, but oh well, quake is quake)
-                               // LordHavoc: figured out bobup: the time at which the sin is at 180
-                               // degrees (which allows lengthening or squishing the peak or valley)
-                               cycle = cl.time / cl_bobcycle.value;
-                               cycle -= (int) cycle;
-                               if (cycle < cl_bobup.value)
-                                       cycle = sin(M_PI * cycle / cl_bobup.value);
-                               else
-                                       cycle = sin(M_PI + M_PI * (cycle-cl_bobup.value)/(1.0 - cl_bobup.value));
-                               // bob is proportional to velocity in the xy plane
-                               // (don't count Z, or jumping messes it up)
-                               bob = sqrt(cl.velocity[0]*cl.velocity[0] + cl.velocity[1]*cl.velocity[1]) * cl_bob.value;
-                               bob = bob*0.3 + bob*0.7*cycle;
-                               r_refdef.vieworg[2] += bound(-7, bob, 4);
+                               // observing entity from third person
+                               vec_t camback, camup, dist, forward[3], chase_dest[3];
+
+                               camback = bound(0, chase_back.value, 128);
+                               if (chase_back.value != camback)
+                                       Cvar_SetValueQuick(&chase_back, camback);
+                               camup = bound(-48, chase_up.value, 96);
+                               if (chase_up.value != camup)
+                                       Cvar_SetValueQuick(&chase_up, camup);
+
+                               // this + 22 is to match view_ofs for compatibility with older versions
+                               camup += 22;
+
+                               if (gamemode == GAME_GOODVSBAD2 && chase_stevie.integer)
+                               {
+                                       // look straight down from high above
+                                       viewangles[0] = 90;
+                                       camback = 2048;
+                               }
+                               AngleVectors(viewangles, forward, NULL, NULL);
+
+                               // trace a little further so it hits a surface more consistently (to avoid 'snapping' on the edge of the range)
+                               dist = -camback - 8;
+                               chase_dest[0] = vieworg[0] + forward[0] * dist;
+                               chase_dest[1] = vieworg[1] + forward[1] * dist;
+                               chase_dest[2] = vieworg[2] + forward[2] * dist + camup;
+                               trace = CL_TraceBox(vieworg, vec3_origin, vec3_origin, chase_dest, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, false);
+                               VectorMAMAM(1, trace.endpos, 8, forward, 4, trace.plane.normal, vieworg);
                        }
-                       // link the delayed viewmodel entities
-                       if (numviewmodels > 0 && r_drawviewmodel.integer && !chase_active.integer && !envmap && r_drawentities.integer && !(cl.items & IT_INVISIBILITY) && cl.stats[STAT_HEALTH] > 0)
+                       else
                        {
-                               int i;
-                               entity_t *ent;
-                               matrix4x4_t matrix, matrix2;
-                               Matrix4x4_CreateFromQuakeEntity(&matrix, r_refdef.vieworg[0], r_refdef.vieworg[1], r_refdef.vieworg[2], r_refdef.viewangles[0] + v_idlescale.value * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value, r_refdef.viewangles[1] - v_idlescale.value * sin(cl.time*v_ipitch_cycle.value) * v_ipitch_level.value, r_refdef.viewangles[2] - v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value, 0.3);
-                               for (i = 0;i < numviewmodels && r_refdef.numentities < r_refdef.maxentities;i++)
+                               // first person view from entity
+                               // angles
+                               if (cl.stats[STAT_HEALTH] <= 0 && v_deathtilt.integer)
+                                       viewangles[ROLL] = 80;  // dead view angle
+                               VectorAdd(viewangles, cl.punchangle, viewangles);
+                               viewangles[ROLL] += V_CalcRoll(cl.viewangles, cl.movement_velocity);
+                               if (v_dmg_time > 0)
+                               {
+                                       viewangles[ROLL] += v_dmg_time/v_kicktime.value*v_dmg_roll;
+                                       viewangles[PITCH] += v_dmg_time/v_kicktime.value*v_dmg_pitch;
+                                       v_dmg_time -= cl.frametime;
+                               }
+                               // origin
+                               VectorAdd(vieworg, cl.punchvector, vieworg);
+                               vieworg[2] += cl.stats[STAT_VIEWHEIGHT];
+                               if (cl.stats[STAT_HEALTH] > 0 && cl_bob.value && cl_bobcycle.value)
                                {
-                                       ent = viewmodels[i];
-                                       r_refdef.entities[r_refdef.numentities++] = &ent->render;
-                                       matrix2 = ent->render.matrix;
-                                       Matrix4x4_Concat(&ent->render.matrix, &matrix, &matrix2);
-                                       Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
-                                       CL_BoundingBoxForEntity(&ent->render);
+                                       double bob, cycle;
+                                       // LordHavoc: this code is *weird*, but not replacable (I think it
+                                       // should be done in QC on the server, but oh well, quake is quake)
+                                       // LordHavoc: figured out bobup: the time at which the sin is at 180
+                                       // degrees (which allows lengthening or squishing the peak or valley)
+                                       cycle = cl.time / cl_bobcycle.value;
+                                       cycle -= (int) cycle;
+                                       if (cycle < cl_bobup.value)
+                                               cycle = sin(M_PI * cycle / cl_bobup.value);
+                                       else
+                                               cycle = sin(M_PI + M_PI * (cycle-cl_bobup.value)/(1.0 - cl_bobup.value));
+                                       // bob is proportional to velocity in the xy plane
+                                       // (don't count Z, or jumping messes it up)
+                                       bob = sqrt(cl.movement_velocity[0]*cl.movement_velocity[0] + cl.movement_velocity[1]*cl.movement_velocity[1]) * cl_bob.value;
+                                       bob = bob*0.3 + bob*0.7*cycle;
+                                       vieworg[2] += bound(-7, bob, 4);
                                }
                        }
+                       // calculate a view matrix for rendering the scene
+                       if (v_idlescale.value)
+                               Matrix4x4_CreateFromQuakeEntity(&r_refdef.viewentitymatrix, vieworg[0], vieworg[1], vieworg[2], viewangles[0] + v_idlescale.value * sin(cl.time*v_ipitch_cycle.value) * v_ipitch_level.value, viewangles[1] + v_idlescale.value * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value, viewangles[2] + v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value, 1);
+                       else
+                               Matrix4x4_CreateFromQuakeEntity(&r_refdef.viewentitymatrix, vieworg[0], vieworg[1], vieworg[2], viewangles[0], viewangles[1], viewangles[2] + v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value, 1);
+                       // calculate a viewmodel matrix for use in view-attached entities
+                       Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, vieworg[0], vieworg[1], vieworg[2], viewangles[0], viewangles[1], viewangles[2], 0.3);
                }
+       }
+}
 
-               // drop the damage value
-               cl.cshifts[CSHIFT_DAMAGE].percent -= (cl.time - cl.oldtime)*150;
-               if (cl.cshifts[CSHIFT_DAMAGE].percent <= 0)
-                       cl.cshifts[CSHIFT_DAMAGE].percent = 0;
-
-               // drop the bonus value
-               cl.cshifts[CSHIFT_BONUS].percent -= (cl.time - cl.oldtime)*100;
-               if (cl.cshifts[CSHIFT_BONUS].percent <= 0)
-                       cl.cshifts[CSHIFT_BONUS].percent = 0;
+void V_FadeViewFlashs(void)
+{
+       // drop the damage value
+       cl.cshifts[CSHIFT_DAMAGE].percent -= (cl.time - cl.oldtime)*150;
+       if (cl.cshifts[CSHIFT_DAMAGE].percent <= 0)
+               cl.cshifts[CSHIFT_DAMAGE].percent = 0;
+       // drop the bonus value
+       cl.cshifts[CSHIFT_BONUS].percent -= (cl.time - cl.oldtime)*100;
+       if (cl.cshifts[CSHIFT_BONUS].percent <= 0)
+               cl.cshifts[CSHIFT_BONUS].percent = 0;
+}
 
+void V_CalcViewBlend(void)
+{
+       float a2;
+       int j;
+       r_refdef.viewblend[0] = 0;
+       r_refdef.viewblend[1] = 0;
+       r_refdef.viewblend[2] = 0;
+       r_refdef.viewblend[3] = 0;
+       r_refdef.fovscale_x = cl.viewzoom;
+       r_refdef.fovscale_y = cl.viewzoom;
+       if (cls.state == ca_connected && cls.signon == SIGNONS && gl_polyblend.value > 0)
+       {
                // set contents color
-               switch (CL_PointContents(r_refdef.vieworg))
+               int supercontents;
+               vec3_t vieworigin;
+               Matrix4x4_OriginFromMatrix(&r_refdef.viewentitymatrix, vieworigin);
+               supercontents = CL_PointSuperContents(vieworigin);
+               if (supercontents & SUPERCONTENTS_LIQUIDSMASK)
                {
-               case CONTENTS_EMPTY:
-               case CONTENTS_SOLID:
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[0] = v_cshift.destcolor[0];
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[1] = v_cshift.destcolor[1];
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[2] = v_cshift.destcolor[2];
-                       cl.cshifts[CSHIFT_CONTENTS].percent = v_cshift.percent;
-                       break;
-               case CONTENTS_LAVA:
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[0] = 255;
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[1] = 80;
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[2] = 0;
-                       cl.cshifts[CSHIFT_CONTENTS].percent = 150 >> 1;
-                       break;
-               case CONTENTS_SLIME:
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[0] = 0;
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[1] = 25;
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[2] = 5;
+                       r_refdef.fovscale_x *= 1 - (((sin(cl.time * 4.7) + 1) * 0.015) * r_waterwarp.value);
+                       r_refdef.fovscale_y *= 1 - (((sin(cl.time * 3.0) + 1) * 0.015) * r_waterwarp.value);
+                       if (supercontents & SUPERCONTENTS_LAVA)
+                       {
+                               cl.cshifts[CSHIFT_CONTENTS].destcolor[0] = 255;
+                               cl.cshifts[CSHIFT_CONTENTS].destcolor[1] = 80;
+                               cl.cshifts[CSHIFT_CONTENTS].destcolor[2] = 0;
+                       }
+                       else if (supercontents & SUPERCONTENTS_SLIME)
+                       {
+                               cl.cshifts[CSHIFT_CONTENTS].destcolor[0] = 0;
+                               cl.cshifts[CSHIFT_CONTENTS].destcolor[1] = 25;
+                               cl.cshifts[CSHIFT_CONTENTS].destcolor[2] = 5;
+                       }
+                       else
+                       {
+                               cl.cshifts[CSHIFT_CONTENTS].destcolor[0] = 130;
+                               cl.cshifts[CSHIFT_CONTENTS].destcolor[1] = 80;
+                               cl.cshifts[CSHIFT_CONTENTS].destcolor[2] = 50;
+                       }
                        cl.cshifts[CSHIFT_CONTENTS].percent = 150 >> 1;
-                       break;
-               default:
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[0] = 130;
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[1] = 80;
-                       cl.cshifts[CSHIFT_CONTENTS].destcolor[2] = 50;
-                       cl.cshifts[CSHIFT_CONTENTS].percent = 128 >> 1;
                }
-
-               if (cl.items & IT_QUAD)
-               {
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 0;
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 0;
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 255;
-                       cl.cshifts[CSHIFT_POWERUP].percent = 30;
-               }
-               else if (cl.items & IT_SUIT)
-               {
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 0;
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 255;
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 0;
-                       cl.cshifts[CSHIFT_POWERUP].percent = 20;
-               }
-               else if (cl.items & IT_INVISIBILITY)
+               else
                {
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 100;
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 100;
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 100;
-                       cl.cshifts[CSHIFT_POWERUP].percent = 100;
+                       cl.cshifts[CSHIFT_CONTENTS].destcolor[0] = 0;
+                       cl.cshifts[CSHIFT_CONTENTS].destcolor[1] = 0;
+                       cl.cshifts[CSHIFT_CONTENTS].destcolor[2] = 0;
+                       cl.cshifts[CSHIFT_CONTENTS].percent = 0;
                }
-               else if (cl.items & IT_INVULNERABILITY)
+
+               if (gamemode != GAME_TRANSFUSION)
                {
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 255;
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 255;
-                       cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 0;
-                       cl.cshifts[CSHIFT_POWERUP].percent = 30;
+                       if (cl.stats[STAT_ITEMS] & IT_QUAD)
+                       {
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 0;
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 0;
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 255;
+                               cl.cshifts[CSHIFT_POWERUP].percent = 30;
+                       }
+                       else if (cl.stats[STAT_ITEMS] & IT_SUIT)
+                       {
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 0;
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 255;
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 0;
+                               cl.cshifts[CSHIFT_POWERUP].percent = 20;
+                       }
+                       else if (cl.stats[STAT_ITEMS] & IT_INVISIBILITY)
+                       {
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 100;
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 100;
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 100;
+                               cl.cshifts[CSHIFT_POWERUP].percent = 100;
+                       }
+                       else if (cl.stats[STAT_ITEMS] & IT_INVULNERABILITY)
+                       {
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 255;
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 255;
+                               cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 0;
+                               cl.cshifts[CSHIFT_POWERUP].percent = 30;
+                       }
+                       else
+                               cl.cshifts[CSHIFT_POWERUP].percent = 0;
                }
-               else
-                       cl.cshifts[CSHIFT_POWERUP].percent = 0;
 
-               // LordHavoc: fixed V_CalcBlend
-               r = 0;
-               g = 0;
-               b = 0;
-               a = 0;
+               cl.cshifts[CSHIFT_VCSHIFT].destcolor[0] = v_cshift.destcolor[0];
+               cl.cshifts[CSHIFT_VCSHIFT].destcolor[1] = v_cshift.destcolor[1];
+               cl.cshifts[CSHIFT_VCSHIFT].destcolor[2] = v_cshift.destcolor[2];
+               cl.cshifts[CSHIFT_VCSHIFT].percent = v_cshift.percent;
 
-               for (j=0 ; j<NUM_CSHIFTS ; j++)
+               // LordHavoc: fixed V_CalcBlend
+               for (j = 0;j < NUM_CSHIFTS;j++)
                {
-                       a2 = cl.cshifts[j].percent * (1.0f / 255.0f);
-
-                       if (a2 < 0)
-                               continue;
-                       if (a2 > 1)
-                               a2 = 1;
-                       r += (cl.cshifts[j].destcolor[0]-r) * a2;
-                       g += (cl.cshifts[j].destcolor[1]-g) * a2;
-                       b += (cl.cshifts[j].destcolor[2]-b) * a2;
-                       a = 1 - (1 - a) * (1 - a2); // correct alpha multiply...  took a while to find it on the web
+                       a2 = bound(0.0f, cl.cshifts[j].percent * (1.0f / 255.0f), 1.0f);
+                       if (a2 > 0)
+                       {
+                               VectorLerp(r_refdef.viewblend, a2, cl.cshifts[j].destcolor, r_refdef.viewblend);
+                               r_refdef.viewblend[3] = (1 - (1 - r_refdef.viewblend[3]) * (1 - a2)); // correct alpha multiply...  took a while to find it on the web
+                       }
                }
                // saturate color (to avoid blending in black)
-               if (a)
+               if (r_refdef.viewblend[3])
                {
-                       a2 = 1 / a;
-                       r *= a2;
-                       g *= a2;
-                       b *= a2;
+                       a2 = 1 / r_refdef.viewblend[3];
+                       VectorScale(r_refdef.viewblend, a2, r_refdef.viewblend);
                }
 
-               r_refdef.viewblend[0] = bound(0, r * (1.0/255.0), 1);
-               r_refdef.viewblend[1] = bound(0, g * (1.0/255.0), 1);
-               r_refdef.viewblend[2] = bound(0, b * (1.0/255.0), 1);
-               r_refdef.viewblend[3] = bound(0, a              , 1);
-       }
-       else
-       {
-               cl.cshifts[CSHIFT_DAMAGE].percent = 0;
-               cl.cshifts[CSHIFT_BONUS].percent = 0;
-               cl.cshifts[CSHIFT_CONTENTS].percent = 0;
-               cl.cshifts[CSHIFT_POWERUP].percent = 0;
-               r_refdef.viewblend[0] = 0;
-               r_refdef.viewblend[1] = 0;
-               r_refdef.viewblend[2] = 0;
-               r_refdef.viewblend[3] = 0;
+               r_refdef.viewblend[0] = bound(0.0f, r_refdef.viewblend[0] * (1.0f/255.0f), 1.0f);
+               r_refdef.viewblend[1] = bound(0.0f, r_refdef.viewblend[1] * (1.0f/255.0f), 1.0f);
+               r_refdef.viewblend[2] = bound(0.0f, r_refdef.viewblend[2] * (1.0f/255.0f), 1.0f);
+               r_refdef.viewblend[3] = bound(0.0f, r_refdef.viewblend[3] * gl_polyblend.value, 1.0f);
        }
 }
 
@@ -538,5 +590,15 @@ void V_Init (void)
        Cvar_RegisterVariable (&v_kicktime);
        Cvar_RegisterVariable (&v_kickroll);
        Cvar_RegisterVariable (&v_kickpitch);
+
+       Cvar_RegisterVariable (&cl_stairsmoothspeed);
+
+       Cvar_RegisterVariable (&chase_back);
+       Cvar_RegisterVariable (&chase_up);
+       Cvar_RegisterVariable (&chase_active);
+       if (gamemode == GAME_GOODVSBAD2)
+               Cvar_RegisterVariable (&chase_stevie);
+
+       Cvar_RegisterVariable (&v_deathtilt.integer);
 }