]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/view.qc
Shownames: fade when moving to spectate
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / view.qc
index a6d05d9a62cd24ca8a9ea2f15f75b353b79feb55..f2792d0bb1f542e22f2e705f441332f69aba4f38 100644 (file)
@@ -252,25 +252,32 @@ void viewmodel_animate(entity this)
                        t *= 5;
                }
                bspeed = xyspeed * 0.01;
-               MAKEVECTORS(makevectors, gunangles, forward, right, up);
+               MAKEVECTORS(makevectors, view_angles, forward, right, up);
                float bobr = bspeed * autocvar_cl_bobmodel_side * autocvar_cl_viewmodel_scale * sin(s) * t;
                gunorg += bobr * right;
                float bobu = bspeed * autocvar_cl_bobmodel_up * autocvar_cl_viewmodel_scale * cos(s * 2) * t;
                gunorg += bobu * up;
        }
-       this.origin += view_forward * gunorg.x + view_right * gunorg.y + view_up * gunorg.z;
+       vector v = rotate(gunorg, YAW(view_angles) * DEG2RAD); // rotate world coordinates to relative ones
+       v.z = gunorg.z;
+       this.origin += v;
        gunangles.x = -gunangles.x; // pitch was inverted, now that actually matters
        this.angles += gunangles;
 }
 
 .vector viewmodel_origin, viewmodel_angles;
+.float weapon_nextthink;
+.float weapon_eta_last;
+.float weapon_switchdelay;
 
 void viewmodel_draw(entity this)
 {
        int mask = (intermission || (getstati(STAT_HEALTH) <= 0) || autocvar_chase_active) ? 0 : MASK_NORMAL;
        float a = this.alpha;
        int c = stof(getplayerkeyvalue(current_player, "colors"));
-       vector g = this.glowmod; // TODO: completely clientside: colormapPaletteColor(c & 0x0F, true) * 2;
+       vector g;
+       Weapon wep = Weapons_from(activeweapon);
+       if (!(g = wep.wr_glow(wep))) g = colormapPaletteColor(c & 0x0F, true) * 2;
        entity me = CSQCModel_server2csqc(player_localentnum - 1);
        int fx = ((me.csqcmodel_effects & EFMASK_CHEAP)
                | EF_NODEPTHTEST)
@@ -279,7 +286,7 @@ void viewmodel_draw(entity this)
        {
                e.drawmask = mask;
                e.alpha = a;
-               e.colormap = c;
+               e.colormap = 256 + c;  // colormap == 0 is black, c == 0 is white
                e.glowmod = g;
                e.csqcmodel_effects = fx;
                WITH(entity, self, e, CSQCModel_Effects_Apply());
@@ -298,22 +305,19 @@ void viewmodel_draw(entity this)
                if (!this.animstate_override)
                        anim_set(this, this.anim_idle, true, false, false);
        }
-       float eta = (STAT(WEAPON_NEXTTHINK) - time); // TODO: / W_WeaponRateFactor();
        float f = 0; // 0..1; 0: fully active
-       switch (this.state)
+       float eta = (this.weapon_nextthink - time) / STAT(WEAPONRATEFACTOR);
+       if (eta <= 0) f = this.weapon_eta_last;
+       else switch (this.state)
        {
                case WS_RAISE:
                {
-                       // entity newwep = Weapons_from(activeweapon);
-                       float delay = 0.2; // TODO: newwep.switchdelay_raise;
-                       f = eta / max(eta, delay);
+                       f = eta / max(eta, this.weapon_switchdelay);
                        break;
                }
                case WS_DROP:
                {
-                       // entity oldwep = Weapons_from(activeweapon);
-                       float delay = 0.2; // TODO: newwep.switchdelay_drop;
-                       f = 1 - eta / max(eta, delay);
+                       f = 1 - eta / max(eta, this.weapon_switchdelay);
                        break;
                }
                case WS_CLEAR:
@@ -322,6 +326,7 @@ void viewmodel_draw(entity this)
                        break;
                }
        }
+       this.weapon_eta_last = f;
        this.origin = this.viewmodel_origin;
        this.angles = this.viewmodel_angles;
        this.angles_x = (-90 * f * f);
@@ -605,7 +610,7 @@ float EnemyHitCheck()
                return SHOTTYPE_HITWORLD;
        if(n > maxclients)
                return SHOTTYPE_HITWORLD;
-       t = GetPlayerColor(n - 1);
+       t = entcs_GetTeam(n - 1);
        if(teamplay)
                if(t == myteam)
                        return SHOTTYPE_HITTEAM;
@@ -1415,7 +1420,7 @@ void CSQC_UpdateView(float w, float h)
                current_player = player_localentnum - 1;
        else // then player_localentnum is the vehicle I'm driving
                current_player = player_localnum;
-       myteam = GetPlayerColor(current_player);
+       myteam = entcs_GetTeam(current_player);
 
        if(myteam != prev_myteam)
        {