]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/csqcmodel_hooks.qc
Merge remote-tracking branch 'origin/Mario/arena_nuke'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / csqcmodel_hooks.qc
index 417518444ab826df676021a1ea2d834d37d4414b..848c632773404b03f3e2b2f5cdea611483e78a17 100644 (file)
@@ -69,7 +69,7 @@ void CSQCPlayer_LOD_Apply(void)
        }
 }
 
-// FEATURE: forcemodel (MUST be called BEFORE LOD!)
+// FEATURE: forcemodel and model color selection (MUST be called BEFORE LOD!)
 string forceplayermodels_model;
 float forceplayermodels_modelisgoodmodel;
 float forceplayermodels_modelindex;
@@ -93,97 +93,16 @@ string forceplayermodels_goodmodel;
 float forceplayermodels_goodmodelindex;
 
 .vector glowmod;
-void CSQCPlayer_ColorSelection_Apply(float islocalplayer, float cm)
-{
-       float selected_colormap = self.colormap;
-       // forceplayercolors too
-       if(teamplay)
-       {
-               // own team's color is never forced
-               float forcecolor_friend = 0;
-               float forcecolor_enemy = 0;
-               float teams_count = 0;
-               entity tm;
+.vector old_glowmod;
 
-               for(tm = teams.sort_next; tm; tm = tm.sort_next)
-                       if(tm.team != NUM_SPECTATOR)
-                               ++teams_count;
-
-               if(autocvar_cl_forcemyplayercolors)
-                       forcecolor_friend = 1024 + autocvar_cl_forcemyplayercolors;
-               if(autocvar_cl_forceplayercolors && teams_count == 2)
-                       forcecolor_enemy = 1024 + autocvar__cl_color;
-
-               if(forcecolor_enemy && !forcecolor_friend)
-               {
-                       // only enemy color is forced?
-                       // verify it is not equal to the friend color
-                       if(forcecolor_enemy == 1024 + 17 * myteam)
-                               forcecolor_enemy = 0;
-               }
-
-               if(forcecolor_friend && !forcecolor_enemy)
-               {
-                       // only friend color is forced?
-                       // verify it is not equal to the enemy color
-                       for(tm = teams.sort_next; tm; tm = tm.sort_next)
-                               // note: we even compare against our own team.
-                               // if we rejected because we matched our OWN team color,
-                               // this is not bad; we then simply keep our color as is
-                               // anyway.
-                               if(forcecolor_friend == 1024 + 17 * tm.team)
-                                       forcecolor_friend = 0;
-               }
-
-               if(cm == 1024 + 17 * myteam)
-               {
-                       if(forcecolor_friend)
-                               selected_colormap = forcecolor_friend;
-               }
-               else
-               {
-                       if(forcecolor_enemy)
-                               selected_colormap = forcecolor_enemy;
-               }
-       }
-       else
-       {
-               if(autocvar_cl_forcemyplayercolors && islocalplayer)
-                       selected_colormap = 1024 + autocvar_cl_forcemyplayercolors;
-               else if(autocvar_cl_forceplayercolors)
-                       selected_colormap = player_localnum + 1;
-       }
-
-       if(selected_colormap > 0)
-               self.glowmod = colormapPaletteColor(((selected_colormap >= 1024) ? selected_colormap : stof(getplayerkeyvalue(selected_colormap - 1, "colors"))) & 0x0F, TRUE) * 2;
-       else
-               self.glowmod = '1 1 1';
-
-       if(autocvar_cl_deathglow > 0)
-       {
-               if(self.csqcmodel_isdead)
-               {
-                       selected_colormap = 0;
-                       self.glowmod = self.glowmod * bound(0, 1 - (time - self.death_time) / autocvar_cl_deathglow, 1);
-                       // prevent the zero vector
-                       self.glowmod_x = max(self.glowmod_x, 0.0001);
-                       self.glowmod_y = max(self.glowmod_y, 0.0001);
-                       self.glowmod_z = max(self.glowmod_z, 0.0001);
-               }
-       }
-       self.colormap = selected_colormap;
-
-       print(sprintf("CSQCPlayer_GlowMod_Apply(): state = %s, colormap = %f, glowmod = %s\n", (self.csqcmodel_isdead ? "DEAD" : "ALIVE"), selected_colormap, vtos(self.glowmod)));
-}
-
-void CSQCPlayer_ForceModel_PreUpdate(void)
+void CSQCPlayer_ModelAppearance_PreUpdate(void)
 {
        self.model = self.forceplayermodels_savemodel;
        self.modelindex = self.forceplayermodels_savemodelindex;
        self.skin = self.forceplayermodels_saveskin;
        self.colormap = self.forceplayermodels_savecolormap;
 }
-void CSQCPlayer_ForceModel_PostUpdate(void)
+void CSQCPlayer_ModelAppearance_PostUpdate(void)
 {
        self.forceplayermodels_savemodel = self.model;
        self.forceplayermodels_savemodelindex = self.modelindex;
@@ -200,8 +119,9 @@ void CSQCPlayer_ForceModel_PostUpdate(void)
 }
 void CSQCPlayer_ModelAppearance_Apply(float islocalplayer)
 {
+       // FORCEMODEL
        // which one is ALWAYS good?
-       if not(forceplayermodels_goodmodel)
+       if (!forceplayermodels_goodmodel)
        {
                entity e;
                e = spawn();
@@ -260,7 +180,7 @@ void CSQCPlayer_ModelAppearance_Apply(float islocalplayer)
        float isfriend;
        float cm;
        cm = self.forceplayermodels_savecolormap;
-       cm = (cm >= 1024) ? cm : (stof(getplayerkeyvalue(self.colormap - 1, "colors")) + 1024);
+       cm = (cm >= 1024) ? cm : (stof(getplayerkeyvalue(cm - 1, "colors")) + 1024);
 
        if(teamplay)
                isfriend = (cm == 1024 + 17 * myteam);
@@ -292,42 +212,88 @@ void CSQCPlayer_ModelAppearance_Apply(float islocalplayer)
                self.skin = self.forceplayermodels_saveskin;
        }
 
-       // now pick the color and glowmod of the model
-       CSQCPlayer_ColorSelection_Apply(islocalplayer, cm);
-}
+       // forceplayercolors too
+       if(teamplay)
+       {
+               // own team's color is never forced
+               float forcecolor_friend = 0;
+               float forcecolor_enemy = 0;
+               float teams_count = 0;
+               entity tm;
 
-/*// FEATURE: auto glowmod
-.vector glowmod;
-void CSQCPlayer_GlowMod_Apply(void)
-{
-       float cm = self.colormap;
+               for(tm = teams.sort_next; tm; tm = tm.sort_next)
+                       if(tm.team != NUM_SPECTATOR)
+                               ++teams_count;
 
-       if(self.csqcmodel_effects & CSQCMODEL_EF_RESPAWNGHOST)
-               cm = 1024;
+               if(autocvar_cl_forcemyplayercolors)
+                       forcecolor_friend = 1024 + autocvar_cl_forcemyplayercolors;
+               if(autocvar_cl_forceplayercolors && teams_count == 2)
+                       forcecolor_enemy = 1024 + autocvar__cl_color;
+
+               if(forcecolor_enemy && !forcecolor_friend)
+               {
+                       // only enemy color is forced?
+                       // verify it is not equal to the friend color
+                       if(forcecolor_enemy == 1024 + 17 * myteam)
+                               forcecolor_enemy = 0;
+               }
+
+               if(forcecolor_friend && !forcecolor_enemy)
+               {
+                       // only friend color is forced?
+                       // verify it is not equal to the enemy color
+                       for(tm = teams.sort_next; tm; tm = tm.sort_next)
+                               // note: we even compare against our own team.
+                               // if we rejected because we matched our OWN team color,
+                               // this is not bad; we then simply keep our color as is
+                               // anyway.
+                               if(forcecolor_friend == 1024 + 17 * tm.team)
+                                       forcecolor_friend = 0;
+               }
+
+               if(cm == 1024 + 17 * myteam)
+               {
+                       if(forcecolor_friend)
+                               self.colormap = forcecolor_friend;
+               }
+               else
+               {
+                       if(forcecolor_enemy)
+                               self.colormap = forcecolor_enemy;
+               }
+       }
+       else
+       {
+               if(autocvar_cl_forcemyplayercolors && islocalplayer)
+                       self.colormap = 1024 + autocvar_cl_forcemyplayercolors;
+               else if(autocvar_cl_forceplayercolors)
+                       self.colormap = player_localnum + 1;
+       }
 
+       // GLOWMOD AND DEATH FADING
        if(self.colormap > 0)
                self.glowmod = colormapPaletteColor(((self.colormap >= 1024) ? self.colormap : stof(getplayerkeyvalue(self.colormap - 1, "colors"))) & 0x0F, TRUE) * 2;
        else
                self.glowmod = '1 1 1';
 
-       if(self.colormod != '0 0 0') { self.colormod = '0 0 0'; }
-
        if(autocvar_cl_deathglow > 0)
        {
                if(self.csqcmodel_isdead)
                {
+                       // Fade out to black now...
+                       if(self.old_glowmod == '0 0 0') { self.old_glowmod = self.glowmod; }
                        self.colormap = 0;
-                       self.glowmod = self.glowmod * bound(0, 1 - (time - self.death_time) / autocvar_cl_deathglow, 1);
-                       // prevent the zero vector
+
+                       self.glowmod = self.old_glowmod * bound(0, 1 - (time - self.death_time) / autocvar_cl_deathglow, 1);
                        self.glowmod_x = max(self.glowmod_x, 0.0001);
                        self.glowmod_y = max(self.glowmod_y, 0.0001);
                        self.glowmod_z = max(self.glowmod_z, 0.0001);
                }
-               
+               else if(self.old_glowmod != '0 0 0') { self.old_glowmod = '0 0 0'; }
        }
-       
-       print(sprintf("CSQCPlayer_GlowMod_Apply(): state = %s, colormap = %f, colormod = %s, glowmod = %s\n", (self.csqcmodel_isdead ? "DEAD" : "ALIVE"), cm, vtos(self.colormod), vtos(self.glowmod)));
-}*/
+
+       //print(sprintf("CSQCPlayer_ModelAppearance_Apply(): state = %s, colormap = %f, glowmod = %s\n", (self.csqcmodel_isdead ? "DEAD" : "ALIVE"), self.colormap, vtos(self.glowmod)));
+}
 
 // FEATURE: fallback frames
 .float csqcmodel_saveframe;
@@ -486,22 +452,22 @@ void CSQCModel_AutoTagIndex_Apply(void)
 }
 
 // FEATURE: EF_NODRAW workalike
-float EF_BRIGHTFIELD   = 1;
-float EF_BRIGHTLIGHT   = 4;
-float EF_DIMLIGHT      = 8;
-float EF_DOUBLESIDED = 32768;
-float EF_NOSELFSHADOW = 65536;
-float EF_DYNAMICMODELLIGHT = 131072;
-float EF_RESTARTANIM_BIT = 1048576;
-float EF_TELEPORT_BIT = 2097152;
-float MF_ROCKET  =   1; // leave a trail
-float MF_GRENADE =   2; // leave a trail
-float MF_GIB     =   4; // leave a trail
-float MF_ROTATE  =   8; // rotate (bonus items)
-float MF_TRACER  =  16; // green split trail
-float MF_ZOMGIB  =  32; // small blood trail
-float MF_TRACER2 =  64; // orange split trail
-float MF_TRACER3 = 128; // purple trail
+const float EF_BRIGHTFIELD     = 1;
+const float EF_BRIGHTLIGHT     = 4;
+const float EF_DIMLIGHT        = 8;
+const float EF_DOUBLESIDED = 32768;
+const float EF_NOSELFSHADOW = 65536;
+const float EF_DYNAMICMODELLIGHT = 131072;
+const float EF_RESTARTANIM_BIT = 1048576;
+const float EF_TELEPORT_BIT = 2097152;
+const float MF_ROCKET  =   1; // leave a trail
+const float MF_GRENADE =   2; // leave a trail
+const float MF_GIB     =   4; // leave a trail
+const float MF_ROTATE  =   8; // rotate (bonus items)
+const float MF_TRACER  =  16; // green split trail
+const float MF_ZOMGIB  =  32; // small blood trail
+const float MF_TRACER2 =  64; // orange split trail
+const float MF_TRACER3 = 128; // purple trail
 .float csqcmodel_effects;
 .float csqcmodel_modelflags;
 void CSQCModel_Effects_PreUpdate(void)
@@ -522,12 +488,12 @@ void CSQCModel_Effects_PostUpdate(void)
 void CSQCModel_Effects_Apply(void)
 {
        float eff = self.csqcmodel_effects;
-       eff &~= CSQCMODEL_EF_RESPAWNGHOST;
+       eff &= ~CSQCMODEL_EF_RESPAWNGHOST;
 
-       self.renderflags &~= (RF_DEPTHHACK | RF_ADDITIVE | RF_FULLBRIGHT | EF_NOSHADOW | RF_USEAXIS);
+       self.renderflags &= ~(RF_DEPTHHACK | RF_ADDITIVE | RF_FULLBRIGHT | EF_NOSHADOW | RF_USEAXIS);
        self.effects = 0;
        self.traileffect = 0;
-                       
+
        if(eff & EF_BRIGHTFIELD)
                self.traileffect = particleeffectnum("TR_NEXUIZPLASMA");
        // ignoring EF_MUZZLEFLASH
@@ -641,8 +607,7 @@ void CSQCModel_Hook_PreDraw(float isplayer)
 
        if(self.isplayermodel) // this checks if it's a player MODEL!
        {
-               float islocalplayer = (self.entnum == player_localnum + 1);
-               CSQCPlayer_ModelAppearance_Apply(islocalplayer);
+               CSQCPlayer_ModelAppearance_Apply(self.entnum == player_localnum + 1);
                CSQCPlayer_LOD_Apply();
                if(!isplayer)
                        CSQCPlayer_FallbackFrame_Apply();
@@ -720,7 +685,7 @@ void CSQCModel_Hook_PreUpdate(float isnew, float isplayer, float islocalplayer)
        {
                if(!isplayer)
                        CSQCPlayer_FallbackFrame_PreUpdate();
-               CSQCPlayer_ForceModel_PreUpdate();
+               CSQCPlayer_ModelAppearance_PreUpdate();
        }
 }
 
@@ -732,7 +697,7 @@ void CSQCModel_Hook_PostUpdate(float isnew, float isplayer, float islocalplayer)
        // save values set by server
        if(self.isplayermodel)
        {
-               CSQCPlayer_ForceModel_PostUpdate();
+               CSQCPlayer_ModelAppearance_PostUpdate();
                if(isplayer)
                        CSQCPlayer_AnimDecide_PostUpdate(isnew);
                else