]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - view.c
cl_deathfade: new effect which makes the screen fade to dark red when you die......
[xonotic/darkplaces.git] / view.c
diff --git a/view.c b/view.c
index 0d623eec7cc3124b1b1e2f7511b6824c1a60e91a..6f99af586487441c75dcd8bf43cb27f2d6fb453e 100644 (file)
--- a/view.c
+++ b/view.c
@@ -242,6 +242,7 @@ void V_ParseDamage (void)
        cl.faceanimtime = cl.time + 0.2;                // put sbar face into pain frame
 
        cl.cshifts[CSHIFT_DAMAGE].percent += 3*count;
+       cl.cshifts[CSHIFT_DAMAGE].alphafade = 150;
        if (cl.cshifts[CSHIFT_DAMAGE].percent < 0)
                cl.cshifts[CSHIFT_DAMAGE].percent = 0;
        if (cl.cshifts[CSHIFT_DAMAGE].percent > 150)
@@ -303,10 +304,30 @@ When you run over an item, the server sends this command
 */
 static void V_BonusFlash_f (void)
 {
-       cl.cshifts[CSHIFT_BONUS].destcolor[0] = 215;
-       cl.cshifts[CSHIFT_BONUS].destcolor[1] = 186;
-       cl.cshifts[CSHIFT_BONUS].destcolor[2] = 69;
-       cl.cshifts[CSHIFT_BONUS].percent = 50;
+       if(Cmd_Argc() == 1)
+       {
+               cl.cshifts[CSHIFT_BONUS].destcolor[0] = 215;
+               cl.cshifts[CSHIFT_BONUS].destcolor[1] = 186;
+               cl.cshifts[CSHIFT_BONUS].destcolor[2] = 69;
+               cl.cshifts[CSHIFT_BONUS].percent = 50;
+               cl.cshifts[CSHIFT_BONUS].alphafade = 100;
+       }
+       else if(Cmd_Argc() >= 4 && Cmd_Argc() <= 6)
+       {
+               cl.cshifts[CSHIFT_BONUS].destcolor[0] = atof(Cmd_Argv(1)) * 255;
+               cl.cshifts[CSHIFT_BONUS].destcolor[1] = atof(Cmd_Argv(2)) * 255;
+               cl.cshifts[CSHIFT_BONUS].destcolor[2] = atof(Cmd_Argv(3)) * 255;
+               if(Cmd_Argc() >= 5)
+                       cl.cshifts[CSHIFT_BONUS].percent = atof(Cmd_Argv(4)) * 255; // yes, these are HEXADECIMAL percent ;)
+               else
+                       cl.cshifts[CSHIFT_BONUS].percent = 50;
+               if(Cmd_Argc() >= 6)
+                       cl.cshifts[CSHIFT_BONUS].alphafade = atof(Cmd_Argv(5)) * 255;
+               else
+                       cl.cshifts[CSHIFT_BONUS].alphafade = 100;
+       }
+       else
+               Con_Printf("usage:\nbf, or bf R G B [A [alphafade]]\n");
 }
 
 /*
@@ -567,11 +588,11 @@ void V_FadeViewFlashs(void)
        if (cl.time <= cl.oldtime)
                return;
        // drop the damage value
-       cl.cshifts[CSHIFT_DAMAGE].percent -= (cl.time - cl.oldtime)*150;
+       cl.cshifts[CSHIFT_DAMAGE].percent -= (cl.time - cl.oldtime)*cl.cshifts[CSHIFT_DAMAGE].alphafade;
        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;
+       cl.cshifts[CSHIFT_BONUS].percent -= (cl.time - cl.oldtime)*cl.cshifts[CSHIFT_BONUS].alphafade;
        if (cl.cshifts[CSHIFT_BONUS].percent <= 0)
                cl.cshifts[CSHIFT_BONUS].percent = 0;
 }
@@ -680,11 +701,25 @@ void V_CalcViewBlend(void)
                        a2 = 1 / r_refdef.viewblend[3];
                        VectorScale(r_refdef.viewblend, a2, r_refdef.viewblend);
                }
-
-               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);
+               // Samual: Ugly hack, I know. But it's the best we can do since
+               // there is no way to detect client states from the engine.
+               if (cl.stats[STAT_HEALTH] <= 0 && cl.stats[STAT_HEALTH] != -666 && 
+                       cl.stats[STAT_HEALTH] != -2342 && cl_deathfade.value > 0)
+               {
+                       cl.deathfade += bound(0.0f, cl_deathfade.value, 2.0f) * max(0.0001, cl.time - cl.oldtime);
+                       r_refdef.viewblend[0] = 0.3f;
+                       r_refdef.viewblend[1] = 0.0f;
+                       r_refdef.viewblend[2] = 0.0f;
+                       r_refdef.viewblend[3] = bound(0.0f, cl.deathfade, 0.9f);
+               }
+               else
+               {
+                       cl.deathfade = 0.0f;
+                       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);
+               }
        }
 }
 
@@ -698,7 +733,7 @@ V_Init
 void V_Init (void)
 {
        Cmd_AddCommand ("v_cshift", V_cshift_f, "sets tint color of view");
-       Cmd_AddCommand ("bf", V_BonusFlash_f, "briefly flashes a bright color tint on view (used when items are picked up)");
+       Cmd_AddCommand ("bf", V_BonusFlash_f, "briefly flashes a bright color tint on view (used when items are picked up); optionally takes R G B [A [alphafade]] arguments to specify how the flash looks");
        Cmd_AddCommand ("centerview", V_StartPitchDrift, "gradually recenter view (stop looking up/down)");
 
        Cvar_RegisterVariable (&v_centermove);