]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
use the hud_panel_weapons_accuracy_colorX system in the scoreboard too
authorFruitieX <rasse@rasse-lappy.localdomain>
Fri, 23 Jul 2010 18:53:12 +0000 (21:53 +0300)
committerFruitieX <rasse@rasse-lappy.localdomain>
Fri, 23 Jul 2010 18:53:12 +0000 (21:53 +0300)
qcsrc/client/View.qc
qcsrc/client/hud.qc
qcsrc/client/hud.qh
qcsrc/client/scoreboard.qc

index 8c642415ddebede591b7cbe57ae4e86c19cb2364..c8076b35012a9894cb66357ddaf582e3e7524a90 100644 (file)
@@ -478,7 +478,6 @@ void CSQC_UpdateView(float w, float h)
                weapontime = time;
                last_weapon = activeweapon;
 
-               entity e;
                e = get_weaponinfo(activeweapon);
                if(e.netname != "")
                        localcmd(strcat("\ncl_hook_activeweapon ", e.netname), "\n");
@@ -1190,6 +1189,18 @@ void CSQC_common_hud(void)
        switch(hud)
        {
                case HUD_NORMAL:
+                       // do some accuracy var caching
+                       float i;
+                       if(!(gametype == GAME_RACE || gametype == GAME_CTS))
+                       {
+                               acc_levels = tokenize(cvar_string("hud_panel_weapons_accuracy_color_levels"));
+                               if (acc_levels > MAX_ACCURACY_LEVELS)
+                                       acc_levels = MAX_ACCURACY_LEVELS;
+
+                               for (i = 0; i < acc_levels; ++i)
+                                       acc_lev[i] = stof(argv(i));
+                       }
+
                        // hud first
                        HUD_Main();
 
index 9e6e7d377061b280abb9cb92a25c37dea39ff0dd..a4e0e9a2097dda82b6e804447ff06db560c79bc9 100644 (file)
@@ -1380,10 +1380,6 @@ float GetAmmoTypeForWep(float i)
        }
 }
 
-#define acc_color(i) stov(cvar_string(strcat("hud_panel_weapons_accuracy_color", ftos(i))))
-#define MAX_ACCURACY_LEVELS 10
-float acc_lev[MAX_ACCURACY_LEVELS];
-
 void HUD_Weapons(void)
 {
        if(!autocvar_hud_panel_weapons && !autocvar__hud_configure)
@@ -1469,17 +1465,6 @@ void HUD_Weapons(void)
        vector wpnpos;
        vector wpnsize;
 
-       float acc_levels;
-       if(autocvar_hud_panel_weapons_accuracy && !(gametype == GAME_RACE || gametype == GAME_CTS))
-       {
-               acc_levels = tokenize(cvar_string("hud_panel_weapons_accuracy_color_levels"));
-               if (acc_levels > MAX_ACCURACY_LEVELS)
-                       acc_levels = MAX_ACCURACY_LEVELS;
-
-               for (i = 0; i < acc_levels; ++i)
-                       acc_lev[i] = stof(argv(i));
-       }
-
        for(i = 0; i < weapon_cnt; ++i)
        {
                wpnpos = pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
index 11a039bec6e69eaed5ffbd811c4e1e30c6b4a3a7..89f5edbdcc3228d8d128d4a1b69f87dbf80181fc 100644 (file)
@@ -16,6 +16,11 @@ float scoreboard_bottom;
 float weapon_hits[WEP_MAXCOUNT];
 float weapon_fired[WEP_MAXCOUNT];
 
+#define acc_color(i) stov(cvar_string(strcat("hud_panel_weapons_accuracy_color", ftos(i))))
+#define MAX_ACCURACY_LEVELS 10
+float acc_lev[MAX_ACCURACY_LEVELS];
+float acc_levels;
+
 float complain_weapon;
 string complain_weapon_name;
 float complain_weapon_type;
index 5efa9118d62bc9a32e4406a939aca739fdaacac4..b0865d32676e575c8b18fa0df2fa66a1c39445cc 100644 (file)
@@ -969,19 +969,26 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                        float padding;
                        padding = ((sbwidth/weapon_cnt) - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value
 
-                       // yellow_accuracy = value at which accuracy becomes yellow
-                       if(weapon_stats >= 100) {
-                               rgb_x = 0;
-                               rgb_y = 1;
-                       }
-                       else if(weapon_stats > autocvar_hud_panel_weapons_accuracy_yellow) {
-                               rgb_x = 1 - (weapon_stats-autocvar_hud_panel_weapons_accuracy_yellow)/(100-autocvar_hud_panel_weapons_accuracy_yellow); // red value between 1 -> 0
-                               rgb_y = 1;
-                       } else {
-                               rgb_x = 1;
-                               rgb_y = weapon_stats/autocvar_hud_panel_weapons_accuracy_yellow; // green value between 0 -> 1
+                       float weapon_hit, weapon_damage;
+                       weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
+                       if(weapon_damage)
+                       {
+                               weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
+                               weapon_stats = floor(100 * weapon_hit / weapon_damage);
                        }
-                       rgb_z = 0;
+
+                       // find the max level lower than weapon_stats
+                       float j;
+                       j = acc_levels-1;
+                       while ( j && weapon_stats < acc_lev[j] )
+                               --j;
+
+                       // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
+                       float factor;
+                       factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
+                       rgb = acc_color(j);
+                       rgb = rgb + factor * (acc_color(j+1) - rgb);
+
                        drawstring(pos + '1 0 0' * padding + '0 1 0' * height * (2/3), s, '1 1 0' * fontsize, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
                }
                pos_x += sbwidth/weapon_cnt * rows;