]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
Merge remote branch 'origin/fruitiex/fruitbalance'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index 82f080241ec829e16518a57aeda26ab130750042..6b21f86a4f281179cdcf8e65807908d0a832fb5c 100644 (file)
@@ -517,7 +517,7 @@ void HUD_Panel_ExportCfg(string cfgname)
                        }
                        fputs(fh, "\n");
                }
-               fputs(fh, strcat("menu_restart", "\n")); // force a menu update when execing config, so that the dialogs are updated
+               fputs(fh, strcat("menu_sync", "\n")); // force the menu to reread the cvars, so that the dialogs are updated
 
                print("^2Successfully exported to hud_", autocvar_hud_skin, "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
        }
@@ -1095,17 +1095,29 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
                        if (bInputType == 1)
                                return true;
 
-                       if (highlightedPanel_copied != -1 && highlightedPanel_prev != -1)
-                       {
-                               // backup first!
-                               panel_pos_backup = panel_pos;
-                               panel_size_backup = panel_size;
-                               highlightedPanel_backup = highlightedPanel_prev;
+                       if (highlightedPanel_copied == -1 || highlightedPanel_prev == -1)
+                               return true;
 
-                               string s;
-                               s = strcat(ftos(panel_size_copied_x/vid_conwidth), " ", ftos(panel_size_copied_y/vid_conheight));
-                               cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
-                       }
+                       HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev)
+
+                       // reduce size if it'd go beyond screen boundaries
+                       vector tmp_size = panel_size_copied;
+                       if (panel_pos_x + panel_size_copied_x > vid_conwidth)
+                               tmp_size_x = vid_conwidth - panel_pos_x;
+                       if (panel_pos_y + panel_size_copied_y > vid_conheight)
+                               tmp_size_y = vid_conheight - panel_pos_y;
+
+                       if (panel_size == tmp_size)
+                               return true;
+
+                       // backup first!
+                       panel_pos_backup = panel_pos;
+                       panel_size_backup = panel_size;
+                       highlightedPanel_backup = highlightedPanel_prev;
+
+                       string s;
+                       s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
+                       cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
                }
                else if(nPrimary == 'z') // undo last action
                {
@@ -1306,7 +1318,7 @@ void HUD_Panel_Highlight()
 }
 
 float highlightcheck;
-float would_backup;
+vector prev_pos, prev_size;
 void HUD_Panel_Mouse()
 {
        // TODO: needs better check... is there any float that contains the current state of the menu? _menu_alpha isn't apparently updated the frame the menu gets enabled
@@ -1335,22 +1347,29 @@ void HUD_Panel_Mouse()
 
        if(mouseClicked)
        {
-               vector prev_pos, prev_size;
                if(prevMouseClicked == 0)
                {
                        HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
                                                                        // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
-                       would_backup = TRUE;
-               }
-               else if (would_backup)
-               {
-                       // this is not the actual backup! Saving pos and size values
-                       // only to check later if they are different from new values
                        prev_pos = panel_pos;
                        prev_size = panel_size;
                }
+               else
+                       HUD_Panel_UpdatePosSizeForId(highlightedPanel)
 
-               hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
+               if (prev_pos != panel_pos || prev_size != panel_size)
+               {
+                       hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
+                       // backup!
+                       panel_pos_backup = prev_pos;
+                       panel_size_backup = prev_size;
+                       highlightedPanel_backup = highlightedPanel;
+               }
+               else
+                       // in case the clicked panel is inside another panel and we aren't
+                       // moving it, avoid the immediate "fix" of its position/size
+                       // (often unwanted and hateful) by disabling collisions check
+                       hud_configure_checkcollisions = false;
 
                if(highlightedAction == 1)
                        HUD_Panel_SetPos(mousepos - panel_click_distance);
@@ -1373,18 +1392,6 @@ void HUD_Panel_Mouse()
                        HUD_Panel_SetPosSize(mySize);
                }
 
-               HUD_Panel_UpdatePosSizeForId(highlightedPanel)
-               if (prevMouseClicked)
-               if (would_backup)
-               if (prev_pos != panel_pos || prev_size != panel_size)
-               {
-                       // backup!
-                       panel_pos_backup = prev_pos;
-                       panel_size_backup = prev_size;
-                       highlightedPanel_backup = highlightedPanel;
-                       would_backup = FALSE;
-               }
-
                // doubleclick check
                if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
                {
@@ -1471,6 +1478,7 @@ float GetAmmoTypeForWep(float i)
                case WEP_UZI: return 1;
                case WEP_CAMPINGRIFLE: return 1;
                case WEP_GRENADE_LAUNCHER: return 2;
+               case WEP_MINE_LAYER: return 2;
                case WEP_ELECTRO: return 3;
                case WEP_CRYLINK: return 3;
                case WEP_HLAC: return 3;
@@ -1607,305 +1615,305 @@ void HUD_Weapons(void)
                heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
        }
 
-               HUD_Panel_DrawBg(1);
-               if(panel_bg_padding)
-               {
-                       panel_pos += '1 1 0' * panel_bg_padding;
-                       panel_size -= '2 2 0' * panel_bg_padding;
-               }
+       HUD_Panel_DrawBg(1);
+       if(panel_bg_padding)
+       {
+               panel_pos += '1 1 0' * panel_bg_padding;
+               panel_size -= '2 2 0' * panel_bg_padding;
+       }
 
-               // hits
-               weapon_stats = getstati(STAT_DAMAGE_HITS);
-               weapon_number = weapon_stats & 63;
-               weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
-               // fired
-               weapon_stats = getstati(STAT_DAMAGE_FIRED);
-               weapon_number = weapon_stats & 63;
-               weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
+       // hits
+       weapon_stats = getstati(STAT_DAMAGE_HITS);
+       weapon_number = weapon_stats & 63;
+       weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
+       // fired
+       weapon_stats = getstati(STAT_DAMAGE_FIRED);
+       weapon_number = weapon_stats & 63;
+       weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
 
-               if(cvar_or("hud_panel_weapons_fade", 1))
-               {
-                       fade = 3.2 - 2 * (time - weapontime);
-                       fade = bound(0.7, fade, 1);
-               }
-               else
-                       fade = 1;
+       if(cvar_or("hud_panel_weapons_fade", 1))
+       {
+               fade = 3.2 - 2 * (time - weapontime);
+               fade = bound(0.7, fade, 1);
+       }
+       else
+               fade = 1;
 
-               HUD_Weapons_Clear();
+       HUD_Weapons_Clear();
 
-               float rows, columns;
-               rows = panel_size_y/panel_size_x;
-               rows = bound(1, floor((sqrt(4 * autocvar_hud_panel_weapons_aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
+       float rows, columns;
+       rows = panel_size_y/panel_size_x;
+       rows = bound(1, floor((sqrt(4 * autocvar_hud_panel_weapons_aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
 
-               columns = ceil(WEP_COUNT/rows);
-               float row, column;
+       columns = ceil(WEP_COUNT/rows);
+       float row, column;
 
-               float a, type, fullammo;
-               float when;
-               when = autocvar_hud_panel_weapons_complainbubble_time;
-               float fadetime;
-               fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
+       float a, type, fullammo;
+       float when;
+       when = autocvar_hud_panel_weapons_complainbubble_time;
+       float fadetime;
+       fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
 
-               vector color;
-               vector wpnpos;
-               vector wpnsize;
+       vector color;
+       vector wpnpos;
+       vector wpnsize;
 
-               for(i = 0; i < weapon_cnt; ++i)
-               {
-                       wpnpos = panel_pos + eX * column * panel_size_x*(1/columns) + eY * row * panel_size_y*(1/rows);
-                       wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
+       for(i = 0; i < weapon_cnt; ++i)
+       {
+               wpnpos = panel_pos + eX * column * panel_size_x*(1/columns) + eY * row * panel_size_y*(1/rows);
+               wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
 
-                       self = weaponorder[i];
-                       weapid = self.impulse;
+               self = weaponorder[i];
+               weapid = self.impulse;
 
-                       // draw background behind currently selected weapon
-                       if(self.weapon == activeweapon)
-                               drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL);
+               // draw background behind currently selected weapon
+               if(self.weapon == activeweapon)
+                       drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL);
 
-                       // draw the weapon accuracy
-                       if(acc_levels)
+               // draw the weapon accuracy
+               if(acc_levels)
+               {
+                       float weapon_hit, weapon_damage;
+                       weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
+                       if(weapon_damage)
                        {
-                               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);
-                               }
+                               weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
+                               weapon_stats = floor(100 * weapon_hit / weapon_damage);
+                       }
 
-                               // find the max level lower than weapon_stats
-                               float j;
-                               j = acc_levels-1;
-                               while ( j && weapon_stats < acc_lev[j] )
-                                       --j;
+                       // 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]);
-                               color = acc_color(j);
-                               color = color + factor * (acc_color(j+1) - color);
+                       // 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]);
+                       color = acc_color(j);
+                       color = color + factor * (acc_color(j+1) - color);
 
-                               if(weapon_damage)
-                                       drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
-                       }
+                       if(weapon_damage)
+                               drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
+               }
 
-                       // draw the weapon icon
-                       if((self.impulse >= 0) && (getstati(STAT_WEAPONS) & self.weapons))
-                       {
-                               drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL);
+               // draw the weapon icon
+               if((self.impulse >= 0) && (getstati(STAT_WEAPONS) & self.weapons))
+               {
+                       drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL);
 
-                               if(autocvar_hud_panel_weapons_label == 1) // weapon number
-                                       drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * panel_size_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-                               else if(autocvar_hud_panel_weapons_label == 2) // bind
-                                       drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * panel_size_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+                       if(autocvar_hud_panel_weapons_label == 1) // weapon number
+                               drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * panel_size_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+                       else if(autocvar_hud_panel_weapons_label == 2) // bind
+                               drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * panel_size_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+
+                       // draw ammo status bar
+                       if(autocvar_hud_panel_weapons_ammo && weapid != WEP_TUBA && weapid != WEP_LASER && weapid != WEP_PORTO)
+                       {
+                               a = 0;
+                               type = GetAmmoTypeForWep(weapid);
+                               if(type != -1)
+                                       a = getstati(GetAmmoStat(type)); // how much ammo do we have?
 
-                               // draw ammo status bar
-                               if(autocvar_hud_panel_weapons_ammo && weapid != WEP_TUBA && weapid != WEP_LASER && weapid != WEP_PORTO)
+                               if(a > 0)
                                {
-                                       a = 0;
-                                       type = GetAmmoTypeForWep(weapid);
-                                       if(type != -1)
-                                               a = getstati(GetAmmoStat(type)); // how much ammo do we have?
+                                       switch(type) {
+                                               case 0: fullammo = autocvar_hud_panel_weapons_ammo_full_shells; break;
+                                               case 1: fullammo = autocvar_hud_panel_weapons_ammo_full_nails; break;
+                                               case 2: fullammo = autocvar_hud_panel_weapons_ammo_full_rockets; break;
+                                               case 3: fullammo = autocvar_hud_panel_weapons_ammo_full_cells; break;
+                                               case 4: fullammo = autocvar_hud_panel_weapons_ammo_full_fuel; break;
+                                               default: fullammo = 60;
+                                       }
+
+                                       vector barsize;
+                                       vector barpos;
+                                       if(wpnsize_x/wpnsize_y > autocvar_hud_panel_weapons_aspect)
+                                       {
+                                               barsize_x = autocvar_hud_panel_weapons_aspect * wpnsize_y;
+                                               barsize_y = wpnsize_y;
 
-                                       if(a > 0)
+                                               barpos_x = wpnpos_x + (wpnsize_x - barsize_x) / 2;
+                                               barpos_y = wpnpos_y;
+                                       }
+                                       else
                                        {
-                                               switch(type) {
-                                                       case 0: fullammo = autocvar_hud_panel_weapons_ammo_full_shells; break;
-                                                       case 1: fullammo = autocvar_hud_panel_weapons_ammo_full_nails; break;
-                                                       case 2: fullammo = autocvar_hud_panel_weapons_ammo_full_rockets; break;
-                                                       case 3: fullammo = autocvar_hud_panel_weapons_ammo_full_cells; break;
-                                                       case 4: fullammo = autocvar_hud_panel_weapons_ammo_full_fuel; break;
-                                                       default: fullammo = 60;
-                                               }
-
-                                               vector barsize;
-                                               vector barpos;
-                                               if(wpnsize_x/wpnsize_y > autocvar_hud_panel_weapons_aspect)
-                                               {
-                                                       barsize_x = autocvar_hud_panel_weapons_aspect * wpnsize_y;
-                                                       barsize_y = wpnsize_y;
-
-                                                       barpos_x = wpnpos_x + (wpnsize_x - barsize_x) / 2;
-                                                       barpos_y = wpnpos_y;
-                                               }
-                                               else
-                                               {
-                                                       barsize_y = 1/autocvar_hud_panel_weapons_aspect * wpnsize_x;
-                                                       barsize_x = wpnsize_x;
-
-                                                       barpos_y = wpnpos_y + (wpnsize_y - barsize_y) / 2;
-                                                       barpos_x = wpnpos_x;
-                                               }
-
-                                               drawsetcliparea(
-                                                       barpos_x,
-                                                       barpos_y,
-                                                       barsize_x * bound(0, a/fullammo, 1),
-                                                       barsize_y);
-                                               drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, autocvar_hud_panel_weapons_ammo_color, panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha, DRAWFLAG_NORMAL);
-                                               drawresetcliparea();
+                                               barsize_y = 1/autocvar_hud_panel_weapons_aspect * wpnsize_x;
+                                               barsize_x = wpnsize_x;
+
+                                               barpos_y = wpnpos_y + (wpnsize_y - barsize_y) / 2;
+                                               barpos_x = wpnpos_x;
                                        }
+
+                                       drawsetcliparea(
+                                               barpos_x,
+                                               barpos_y,
+                                               barsize_x * bound(0, a/fullammo, 1),
+                                               barsize_y);
+                                       drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, autocvar_hud_panel_weapons_ammo_color, panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha, DRAWFLAG_NORMAL);
+                                       drawresetcliparea();
                                }
                        }
+               }
 
-                       // draw a "ghost weapon icon" if you don't have the weapon
-                       else
+               // draw a "ghost weapon icon" if you don't have the weapon
+               else
+               {
+                       drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
+               }
+
+               // draw the complain message
+               if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
+               {
+                       if(fadetime)
                        {
-                               drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
+                               if(complain_weapon_time + when > time)
+                                       a = 1;
+                               else
+                                       a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
                        }
-
-                       // draw the complain message
-                       if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
+                       else
                        {
-                               if(fadetime)
-                               {
-                                       if(complain_weapon_time + when > time)
-                                               a = 1;
-                                       else
-                                               a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
-                               }
+                               if(complain_weapon_time + when > time)
+                                       a = 1;
                                else
-                               {
-                                       if(complain_weapon_time + when > time)
-                                               a = 1;
-                                       else
-                                               a = 0;
-                               }
-
-                               string s;
-                               if(complain_weapon_type == 0) {
-                                       s = "Out of ammo";
-                                       color = autocvar_hud_panel_weapons_complainbubble_color_outofammo;
-                               }
-                               else if(complain_weapon_type == 1) {
-                                       s = "Don't have";
-                                       color = autocvar_hud_panel_weapons_complainbubble_color_donthave;
-                               }
-                               else {
-                                       s = "Unavailable";
-                                       color = autocvar_hud_panel_weapons_complainbubble_color_unavailable;
-                               }
-                               drawpic_aspect_skin(wpnpos + '1 1 0' * autocvar_hud_panel_weapons_complainbubble_padding, "weapon_complainbubble", wpnsize - '2 2 0' * autocvar_hud_panel_weapons_complainbubble_padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
-                               drawstring_aspect(wpnpos + '1 1 0' * autocvar_hud_panel_weapons_complainbubble_padding, s, wpnsize - '2 2 0' * autocvar_hud_panel_weapons_complainbubble_padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
+                                       a = 0;
                        }
 
-                       ++row;
-                       if(row >= rows)
-                       {
-                               row = 0;
-                               ++column;
+                       string s;
+                       if(complain_weapon_type == 0) {
+                               s = "Out of ammo";
+                               color = autocvar_hud_panel_weapons_complainbubble_color_outofammo;
+                       }
+                       else if(complain_weapon_type == 1) {
+                               s = "Don't have";
+                               color = autocvar_hud_panel_weapons_complainbubble_color_donthave;
                        }
+                       else {
+                               s = "Unavailable";
+                               color = autocvar_hud_panel_weapons_complainbubble_color_unavailable;
+                       }
+                       drawpic_aspect_skin(wpnpos + '1 1 0' * autocvar_hud_panel_weapons_complainbubble_padding, "weapon_complainbubble", wpnsize - '2 2 0' * autocvar_hud_panel_weapons_complainbubble_padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawstring_aspect(wpnpos + '1 1 0' * autocvar_hud_panel_weapons_complainbubble_padding, s, wpnsize - '2 2 0' * autocvar_hud_panel_weapons_complainbubble_padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
                }
 
-       }
-
-       // Ammo (#1)
-       //
-       // TODO: macro
-       float GetAmmoItemCode(float i)
-       {
-               switch(i)
+               ++row;
+               if(row >= rows)
                {
-                       case 0: return IT_SHELLS;
-                       case 1: return IT_NAILS;
-                       case 2: return IT_ROCKETS;
-                       case 3: return IT_CELLS;
-                       case 4: return IT_FUEL;
-                       default: return -1;
+                       row = 0;
+                       ++column;
                }
        }
 
-       string GetAmmoPicture(float i)
+}
+
+// Ammo (#1)
+//
+// TODO: macro
+float GetAmmoItemCode(float i)
+{
+       switch(i)
        {
-               switch(i)
-               {
-                       case 0: return "ammo_shells";
-                       case 1: return "ammo_bullets";
-                       case 2: return "ammo_rockets";
-                       case 3: return "ammo_cells";
-                       case 4: return "ammo_fuel";
-                       default: return "";
-               }
+               case 0: return IT_SHELLS;
+               case 1: return IT_NAILS;
+               case 2: return IT_ROCKETS;
+               case 3: return IT_CELLS;
+               case 4: return IT_FUEL;
+               default: return -1;
        }
+}
 
-       void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
+string GetAmmoPicture(float i)
+{
+       switch(i)
        {
-               float a;
-               a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
-               if(autocvar__hud_configure)
-                       a = 100;
-
-               vector color;
-               if(a < 10)
-                       color = '0.7 0 0';
-               else
-                       color = '1 1 1';
-
-               float alpha;
-               if(currently_selected)
-                       alpha = 1;
-               else
-                       alpha = 0.7;
+               case 0: return "ammo_shells";
+               case 1: return "ammo_bullets";
+               case 2: return "ammo_rockets";
+               case 3: return "ammo_cells";
+               case 4: return "ammo_fuel";
+               default: return "";
+       }
+}
 
-               vector newSize, newPos;
-               if(mySize_x/mySize_y > 3)
-               {
-                       newSize_x = 3 * mySize_y;
-                       newSize_y = mySize_y;
+void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
+{
+       float a;
+       a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
+       if(autocvar__hud_configure)
+               a = 100;
 
-                       newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
-                       newPos_y = myPos_y;
-               }
-               else
-               {
-                       newSize_y = 1/3 * mySize_x;
-                       newSize_x = mySize_x;
+       vector color;
+       if(a < 10)
+               color = '0.7 0 0';
+       else
+               color = '1 1 1';
 
-                       newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
-                       newPos_x = myPos_x;
-               }
+       float alpha;
+       if(currently_selected)
+               alpha = 1;
+       else
+               alpha = 0.7;
 
-               vector picpos, numpos;
-               if(autocvar_hud_panel_ammo_iconalign)
-               {
-                       numpos = newPos;
-                       picpos = newPos + eX * 2 * newSize_y;
-               }
-               else
-               {
-                       numpos = newPos + eX * newSize_y;
-                       picpos = newPos;
-               }
+       vector newSize, newPos;
+       if(mySize_x/mySize_y > 3)
+       {
+               newSize_x = 3 * mySize_y;
+               newSize_y = mySize_y;
 
-               if (currently_selected)
-                       drawpic_aspect_skin(newPos, "ammo_current_bg", newSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+               newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
+               newPos_y = myPos_y;
+       }
+       else
+       {
+               newSize_y = 1/3 * mySize_x;
+               newSize_x = mySize_x;
 
-               drawfont = hud_bigfont;
-               if(a > 0)
-                       drawstring_aspect(numpos, ftos(a), eX * (2/3) * newSize_x + eY * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
-               else // "ghost" ammo count
-                       drawstring_aspect(numpos, ftos(a), eX * (2/3) * newSize_x + eY * newSize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
-               drawfont = hud_font;
-               if(a > 0)
-                       drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
-               else // "ghost" ammo icon
-                       drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * newSize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
+               newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
+               newPos_x = myPos_x;
        }
 
-       void HUD_Ammo(void)
+       vector picpos, numpos;
+       if(autocvar_hud_panel_ammo_iconalign)
        {
-               if(!autocvar_hud_panel_ammo && !autocvar__hud_configure)
-                       return;
+               numpos = newPos;
+               picpos = newPos + eX * 2 * newSize_y;
+       }
+       else
+       {
+               numpos = newPos + eX * newSize_y;
+               picpos = newPos;
+       }
 
-               active_panel = HUD_PANEL_AMMO;
-               HUD_Panel_UpdateCvars(ammo);
-               float i, currently_selected;
+       if (currently_selected)
+               drawpic_aspect_skin(newPos, "ammo_current_bg", newSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
 
-               vector pos, mySize;
-               pos = panel_pos;
-               mySize = panel_size;
+       drawfont = hud_bigfont;
+       if(a > 0)
+               drawstring_aspect(numpos, ftos(a), eX * (2/3) * newSize_x + eY * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
+       else // "ghost" ammo count
+               drawstring_aspect(numpos, ftos(a), eX * (2/3) * newSize_x + eY * newSize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
+       drawfont = hud_font;
+       if(a > 0)
+               drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
+       else // "ghost" ammo icon
+               drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * newSize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
+}
+
+void HUD_Ammo(void)
+{
+       if(!autocvar_hud_panel_ammo && !autocvar__hud_configure)
+               return;
+
+       active_panel = HUD_PANEL_AMMO;
+       HUD_Panel_UpdateCvars(ammo);
+       float i, currently_selected;
+
+       vector pos, mySize;
+       pos = panel_pos;
+       mySize = panel_size;
 
-               HUD_Panel_DrawBg(1);
+       HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
                pos += '1 1 0' * panel_bg_padding;
@@ -2248,12 +2256,10 @@ void HUD_HealthArmor(void)
                mySize -= '2 2 0' * panel_bg_padding;
        }
 
-       float armor, health;
+       float armor, health, fuel;
        armor = getstati(STAT_ARMOR);
        health = getstati(STAT_HEALTH);
-
-       float fuel;
-       fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
+       fuel = getstati(STAT_FUEL);
 
        if(autocvar__hud_configure)
        {
@@ -2591,41 +2597,41 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s
                        if (alsoprint)
                                print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
                } else if (type == DEATH_KILL) {
-                       HUD_KillNotify_Push(s1, "", 0, DEATH_KILL, s1));
+                       HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
                        if (alsoprint)
-                               print(sprintf("^1%s^1 couldn't take it anymore\n", s1));
+                               print ("^1",s1, "^1 couldn't take it anymore\n");
                } else if (type == DEATH_ROT) {
-                       HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC, s1));
+                       HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
                        if (alsoprint)
-                               print(sprintf("^1%s^1 died\n", s1));
+                               print ("^1",s1, "^1 died\n");
                } else if (type == DEATH_NOAMMO) {
-                       HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO, s1));
+                       HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
                        if (alsoprint)
-                               print(sprintf("^7%s^7 committed suicide. What's the point of living without ammo?\n", s1));
+                               print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
                } else if (type == DEATH_CAMP) {
-                       HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP, s1));
+                       HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
                        if (alsoprint)
-                               print(sprintf("^1%s^1 thought they found a nice camping ground\n", s1));
+                               print ("^1",s1, "^1 thought they found a nice camping ground\n");
                } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
-                       HUD_KillNotify_Push(s1, "", 0, type, s1));
+                       HUD_KillNotify_Push(s1, "", 0, type);
                        if (alsoprint)
-                               print(sprintf("^1%s^1 didn't become friends with the Lord of Teamplay\n", s1));
+                               print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
                } else if (type == DEATH_CHEAT) {
-                       HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC, s1));
+                       HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
                        if (alsoprint)
-                               print(sprintf("^1%s^1 unfairly eliminated themself\n", s1));
+                               print ("^1",s1, "^1 unfairly eliminated themself\n");
                } else if (type == DEATH_FIRE) {
-                       HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC, s1));
+                       HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
                        if (alsoprint)
-                               print(sprintf("^1%s^1 burned to death\n", s1));
+                               print ("^1",s1, "^1 burned to death\n");
                } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
-                       HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC, s1));
+                       HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
                        if (alsoprint)
-                               print(sprintf("^1%s^1 couldn't resist the urge to self-destruct\n", s1));
+                               print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
                } 
                
                if (stof(s2) > 2) // killcount > 2
-                       print(sprintf("^1%s^1 ended it all after a %s kill spree\n", s1, s2));
+                       print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
        } else if(msg == MSG_KILL) {
                w = DEATH_WEAPONOF(type);
                if(WEP_VALID(w)) {
@@ -2638,9 +2644,9 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s
                        if(alsoprint)
                        {
                                if(gentle) {
-                                       print(sprintf("^1%s^1 took action against a team mate\n", s1));
+                                       print ("^1", s1, "^1 took action against a team mate\n");
                                } else {
-                                       print(sprintf("^1%s^1 mows down a team mate\n", s1));
+                                       print ("^1", s1, "^1 mows down a team mate\n");
                                }
                        }
                        if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
@@ -2747,7 +2753,11 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s
                } else if (type == DEATH_CUSTOM) {
                        HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
                        if(alsoprint)
-                               print ("^1",s2, "^1 ", s1, "\n");
+                               print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
+               } else if (type == DEATH_HURTTRIGGER) {
+                       HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
+                       if(alsoprint)
+                               print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
                } else {
                        HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
                        if(alsoprint)
@@ -2852,11 +2862,11 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s
                } else if (type == DEATH_CUSTOM) {
                        HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
                        if(alsoprint)
-                               print ("^1",s1, "^1 ", s2, "\n");
+                               print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
                } else if (type == DEATH_HURTTRIGGER) {
                        HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
                        if(alsoprint)
-                               print ("^1",s1, "^1 was in the wrong place\n");
+                               print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
                } else if(type == DEATH_TOUCHEXPLODE) {
                        HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
                        if(alsoprint)
@@ -3809,9 +3819,9 @@ void HUD_VoteWindow(void)
        drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a, DRAWFLAG_NORMAL);
 
        // print the yes/no counts
-       s = strcat("Yes (", getcommandkey("not bound", "vyes"), "): ", ftos(vote_yescount));
+       s = strcat("Yes (", getcommandkey("vyes", "vyes"), "): ", ftos(vote_yescount));
        drawstring_aspect(pos + eY * (4/8) * mySize_y, s, eX * 0.5 * mySize_x + eY * (1.5/8) * mySize_y, '0 1 0', a, DRAWFLAG_NORMAL);
-       s = strcat("No (", getcommandkey("not bound", "vno"), "): ", ftos(vote_nocount));
+       s = strcat("No (", getcommandkey("vno", "vno"), "): ", ftos(vote_nocount));
        drawstring_aspect(pos + eX * 0.5 * mySize_x + eY * (4/8) * mySize_y, s, eX * 0.5 * mySize_x + eY * (1.5/8) * mySize_y, '1 0 0', a, DRAWFLAG_NORMAL);
 
        // draw the progress bar backgrounds
@@ -4517,29 +4527,32 @@ void HUD_EngineInfo(void)
                mySize -= '2 2 0' * panel_bg_padding;
        }
 
+       float currentTime = gettime(GETTIME_REALTIME);
        if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
        {
-               frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + frametime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
+               float currentframetime = currentTime - prevfps_time;
+               frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
                frametimeavg2 = frametimeavg1;
                frametimeavg1 = frametimeavg;
                
                float weight;
                weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
-               if(frametime > 0.0001) // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter.
+               if(currentframetime > 0.0001) // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter.
                {
-                       if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/frametime) to make big updates instant
-                               prevfps = (1/frametime);
+                       if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/currentframetime) to make big updates instant
+                               prevfps = (1/currentframetime);
                        prevfps = (1 - weight) * prevfps + weight * (1/frametimeavg); // framecounter just used so there's no need for a new variable, think of it as "frametime average"
                }
+               prevfps_time = currentTime;
        }
        else
        {
                framecounter += 1;
-               if(time - prevfps_time > cvar("hud_panel_engineinfo_framecounter_time"))
+               if(currentTime - prevfps_time > cvar("hud_panel_engineinfo_framecounter_time"))
                {
-                       prevfps = framecounter/cvar("hud_panel_engineinfo_framecounter_time");
+                       prevfps = framecounter/(currentTime - prevfps_time);
                        framecounter = 0;
-                       prevfps_time = time;
+                       prevfps_time = currentTime;
                }
        }
 
@@ -4552,6 +4565,11 @@ void HUD_EngineInfo(void)
 
 // Info messages panel (#14)
 //
+#define drawInfoMessage(s)\
+       if(autocvar_hud_panel_infomessages_flip)\
+               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);\
+       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);\
+       o_y += fontsize_y;
 void HUD_InfoMessages(void)
 {
        if(!autocvar_hud_panel_infomessages && !autocvar__hud_configure)
@@ -4610,35 +4628,22 @@ void HUD_InfoMessages(void)
                                s = "^1Observing";
                        else
                                s = strcat("^1Spectating: ^7", GetPlayerName(spectatee_status - 1));
-
-                       if(autocvar_hud_panel_infomessages_flip)
-                               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                       o += eY * fontsize_y;
+                       drawInfoMessage(s)
 
                        if(spectatee_status == -1)
-                               s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
+                               s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 to spectate");
                        else
-                               s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
-                       if(autocvar_hud_panel_infomessages_flip)
-                               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                       o += eY * fontsize_y;
+                               s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 for another player");
+                       drawInfoMessage(s)
 
                        if(spectatee_status == -1)
                                s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
                        else
-                               s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
-                       if(autocvar_hud_panel_infomessages_flip)
-                               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                       o += eY * fontsize_y;
+                               s = strcat("^1Press ^3", getcommandkey("secondary fire", "+fire2"), "^1 to observe");
+                       drawInfoMessage(s)
 
                        s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
-                       if(autocvar_hud_panel_infomessages_flip)
-                               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                       o += eY * fontsize_y;
+                       drawInfoMessage(s)
 
                        if(gametype == GAME_ARENA)
                                s = "^1Wait for your turn to join";
@@ -4655,10 +4660,7 @@ void HUD_InfoMessages(void)
                        }
                        else
                                s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
-                       if(autocvar_hud_panel_infomessages_flip)
-                               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                       o += eY * fontsize_y;
+                       drawInfoMessage(s)
 
                        //show restart countdown:
                        if (time < getstatf(STAT_GAMESTARTTIME)) {
@@ -4667,16 +4669,13 @@ void HUD_InfoMessages(void)
                                countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
                                s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
                                drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                               o += eY * fontsize_y;
+                               o_y += fontsize_y;
                        }
                }
                if(warmup_stage && !intermission)
                {
                        s = "^2Currently in ^1warmup^2 stage!";
-                       if(autocvar_hud_panel_infomessages_flip)
-                               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                       o += eY * fontsize_y;
+                       drawInfoMessage(s)
                }
 
                string blinkcolor;
@@ -4701,18 +4700,12 @@ void HUD_InfoMessages(void)
                                else
                                        s = strcat("^2Waiting for others to ready up...");
                        }
-                       if(autocvar_hud_panel_infomessages_flip)
-                               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                       o += eY * fontsize_y;
+                       drawInfoMessage(s)
                }
                else if(warmup_stage && !intermission && !spectatee_status)
                {
                        s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
-                       if(autocvar_hud_panel_infomessages_flip)
-                               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                       o += eY * fontsize_y;
+                       drawInfoMessage(s)
                }
 
                if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
@@ -4738,11 +4731,7 @@ void HUD_InfoMessages(void)
                                        if (tm.team != COLOR_SPECTATOR)
                                        if (tm.team_size == ts_max)
                                                s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
-
-                                       if(autocvar_hud_panel_infomessages_flip)
-                                               o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-                                       o += eY * fontsize_y;
+                                       drawInfoMessage(s)
                                }
                        }
                }
@@ -4750,25 +4739,13 @@ void HUD_InfoMessages(void)
        else 
        {
                s = "^7Press ^3ESC ^7to show HUD options.";
-               if(autocvar_hud_panel_infomessages_flip)
-                       o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-               drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-               o += eY * fontsize_y;
+               drawInfoMessage(s)
                s = "^3Doubleclick ^7a panel for panel-specific options.";
-               if(autocvar_hud_panel_infomessages_flip)
-                       o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-               drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-               o += eY * fontsize_y;
+               drawInfoMessage(s)
                s = "^3CTRL ^7to disable collision testing, ^3SHIFT ^7and";
-               if(autocvar_hud_panel_infomessages_flip)
-                       o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-               drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-               o += eY * fontsize_y;
+               drawInfoMessage(s)
                s = "^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.";
-               if(autocvar_hud_panel_infomessages_flip)
-                       o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-               drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
-               o += eY * fontsize_y;
+               drawInfoMessage(s)
        }
 }