]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
Merge remote-tracking branch 'origin/master' into terencehill/spectate_prev
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index a56307e75801190e548d90a05458485bff02096c..469fe67fa27d1524e8f541adaf86602b46f3be90 100644 (file)
@@ -243,9 +243,9 @@ float GetPlayerColorForce(float i)
 float GetPlayerColor(float i)
 {
        if not(playerslots[i].gotscores) // unconnected
-               return FL_SPECTATOR;
+               return NUM_SPECTATOR;
        else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR)
-               return FL_SPECTATOR;
+               return NUM_SPECTATOR;
        else
                return GetPlayerColorForce(i);
 }
@@ -452,7 +452,7 @@ void HUD_Weapons(void)
        float i, f, a;
        float screen_ar, center_x = 0, center_y;
        float weapon_count, weapon_id;
-       float row, column, rows, columns;
+       float row, column, rows = 0, columns;
        float aspect = autocvar_hud_panel_weapons_aspect;
 
        float panel_weapon_accuracy;
@@ -466,10 +466,10 @@ void HUD_Weapons(void)
        vector ammo_color = '1 0 1';
        float ammo_alpha = 1;
 
-       float when = autocvar_hud_panel_weapons_complainbubble_time;
-       float fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
+       float when = max(1, autocvar_hud_panel_weapons_complainbubble_time);
+       float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime);
 
-       vector weapon_pos, weapon_size;
+       vector weapon_pos, weapon_size = '0 0 0';
        local noref vector old_panel_size; // fteqcc sucks
        vector color;
 
@@ -487,11 +487,9 @@ void HUD_Weapons(void)
                        return;
                }
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_WEAPONS;
 
        // update generic hud functions
-       HUD_Panel_UpdateCvars(weapons);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
        draw_beginBoldFont();
@@ -526,6 +524,9 @@ void HUD_Weapons(void)
                weaponorder_cmp_str = string_null;
        }
 
+       if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime)
+               complain_weapon = 0;
+
        // determine which weapons are going to be shown
        if (autocvar_hud_panel_weapons_onlyowned)
        {
@@ -546,27 +547,44 @@ void HUD_Weapons(void)
                                ++weapon_count;
 
                // add it anyway if weaponcomplain is shown
-               if((!autocvar__hud_configure) 
-                       && (autocvar_hud_panel_weapons_complainbubble 
-                               && time - complain_weapon_time < when + fadetime))
-                                       ++weapon_count;
+               if(complain_weapon)
+                       ++weapon_count;
 
                // might as well commit suicide now, no reason to live ;)
-               if (weapon_count == 0) { return; }
-
-               // reduce size of the panel
-               if (panel_size_y > panel_size_x)
+               if (weapon_count == 0)
                {
-                       old_panel_size_y = panel_size_y;
-                       panel_size_y *= weapon_count / WEP_COUNT;
-                       panel_pos_y += (old_panel_size_y - panel_size_y) / 2;
+                       draw_endBoldFont();
+                       return;
                }
-               else
+
+               old_panel_size = panel_size;
+               if(panel_bg_padding)
+                       old_panel_size -= '2 2 0' * panel_bg_padding;
+
+               // first find values for the standard table (with all the weapons)
+               rows = old_panel_size_y/old_panel_size_x;
+               rows = bound(1, floor((sqrt(4 * aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
+               columns = ceil(WEP_COUNT/rows);
+               weapon_size_x = old_panel_size_x / columns;
+               weapon_size_y = old_panel_size_y / rows;
+
+               // change table values to include only the owned weapons
+               // weapon_size won't be changed
+               if(weapon_count <= rows)
                {
-                       old_panel_size_x = panel_size_x;
-                       panel_size_x *= weapon_count / WEP_COUNT;
-                       panel_pos_x += (old_panel_size_x - panel_size_x) / 2;
+                       rows = weapon_count;
+                       columns = 1;
                }
+               else
+                       columns = ceil(weapon_count / rows);
+
+               // reduce size of the panel
+               panel_size_x = columns * weapon_size_x;
+               panel_size_y = rows * weapon_size_y;
+               panel_pos_x += (old_panel_size_x - panel_size_x) / 2;
+               panel_pos_y += (old_panel_size_y - panel_size_y) / 2;
+               if(panel_bg_padding)
+                       panel_size += '2 2 0' * panel_bg_padding;
        }
        else
                weapon_count = WEP_COUNT;
@@ -662,7 +680,10 @@ void HUD_Weapons(void)
        HUD_Panel_DrawBg(1);
 
        if(center_x == -1)
+       {
+               draw_endBoldFont();
                return;
+       }
 
        if(panel_bg_padding)
        {
@@ -671,10 +692,14 @@ void HUD_Weapons(void)
        }
 
        // after the sizing and animations are done, update the other values
-       rows = panel_size_y/panel_size_x;
-       rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count);
-       columns = ceil(weapon_count/rows);
-       weapon_size = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
+
+       if(!rows) // if rows is > 0 onlyowned code has already updated these vars
+       {
+               rows = panel_size_y/panel_size_x;
+               rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count);
+               columns = ceil(weapon_count/rows);
+               weapon_size = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
+       }
 
        // calculate position/size for visual bar displaying ammount of ammo status
        if (autocvar_hud_panel_weapons_ammo)
@@ -706,15 +731,12 @@ void HUD_Weapons(void)
                weapon_id = self.impulse;
 
                // skip if this weapon doesn't exist
-               if (!self || self.impulse < 0) { continue; }
+               if(!self || weapon_id < 0) { continue; }
 
                // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
-               if (autocvar_hud_panel_weapons_onlyowned
-                       && !(WEPSET_CONTAINS_AW(weapons_stat, self.weapon) 
-                       || (self.weapon == complain_weapon 
-                               && time - complain_weapon_time < when + fadetime 
-                               && autocvar_hud_panel_weapons_complainbubble)))
-                                       continue;
+               if(autocvar_hud_panel_weapons_onlyowned)
+               if not(WEPSET_CONTAINS_AW(weapons_stat, self.weapon) || (self.weapon == complain_weapon))
+                       continue;
 
                // figure out the drawing position of weapon
                weapon_pos = (panel_pos 
@@ -796,14 +818,13 @@ void HUD_Weapons(void)
                }
 
                // draw the complain message
-               if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
+               if(self.weapon == complain_weapon)
                {
                        if(fadetime)
                                a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
                        else
                                a = ((complain_weapon_time + when > time) ? 1 : 0);
 
-
                        string s;
                        if(complain_weapon_type == 0) {
                                s = _("Out of ammo");
@@ -927,10 +948,8 @@ void HUD_Ammo(void)
                if(!autocvar_hud_panel_ammo) return;
                if(spectatee_status == -1) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_AMMO;
 
-       HUD_Panel_UpdateCvars(ammo);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
        draw_beginBoldFont();
@@ -1131,14 +1150,12 @@ void HUD_Powerups(void)
        }
        else
        {
-               hud_configure_active_panel = HUD_PANEL_POWERUPS;
-
                strength_time = 15;
                shield_time = 27;
                superweapons_time = 13;
        }
 
-       HUD_Panel_UpdateCvars(powerups);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
        draw_beginBoldFont();
@@ -1374,14 +1391,12 @@ void HUD_HealthArmor(void)
        }
        else
        {
-               hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
-
                health = 150;
                armor = 75;
                fuel = 20;
        }
 
-       HUD_Panel_UpdateCvars(healtharmor);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
        vector pos, mySize;
        pos = panel_pos;
@@ -1605,20 +1620,6 @@ void HUD_HealthArmor(void)
 // Notification area (#4)
 //
 
-string Weapon_SuicideMessage(float deathtype)
-{
-       w_deathtype = deathtype;
-       get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
-       return w_deathtypestring;
-}
-
-string Weapon_KillMessage(float deathtype)
-{
-       w_deathtype = deathtype;
-       get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
-       return w_deathtypestring;
-}
-
 void HUD_Notify_Push(string icon, string attacker, string victim)
 {
        if(icon != "")
@@ -1647,10 +1648,8 @@ void HUD_Notify(void)
        {
                if(!autocvar_hud_panel_notify) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_NOTIFY;
 
-       HUD_Panel_UpdateCvars(notify);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
        vector pos, mySize;
        pos = panel_pos;
@@ -1786,10 +1785,8 @@ void HUD_Timer(void)
        {
                if(!autocvar_hud_panel_timer) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_TIMER;
 
-       HUD_Panel_UpdateCvars(timer);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
        draw_beginBoldFont();
@@ -1856,12 +1853,12 @@ void HUD_Radar(void)
                        if (autocvar_hud_panel_radar != 2 && !teamplay) return;
                }
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_RADAR;
 
-       HUD_Panel_UpdateCvars(radar);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
+       float f = 0;
+
        if (hud_panel_radar_maximized && !autocvar__hud_configure)
        {
                panel_size = autocvar_hud_panel_radar_maximized_size;
@@ -1872,6 +1869,62 @@ void HUD_Radar(void)
                
                panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
                if(precache_pic(panel_bg) == "") { panel_bg = "gfx/hud/default/border_default"; } // fallback
+               
+               switch(hud_panel_radar_maximized_zoommode)
+               {
+                       default:
+                       case 0:
+                               f = current_zoomfraction;
+                               break;
+                       case 1:
+                               f = 1 - current_zoomfraction;
+                               break;
+                       case 2:
+                               f = 0;
+                               break;
+                       case 3:
+                               f = 1;
+                               break;
+               }
+               
+               switch(hud_panel_radar_maximized_rotation)
+               {
+                       case 0:
+                               teamradar_angle = view_angles_y - 90;
+                               break;
+                       default:
+                               teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
+                               break;
+               }
+       }
+       if (!hud_panel_radar_maximized && !autocvar__hud_configure)
+       {
+               switch(hud_panel_radar_zoommode)
+               {
+                       default:
+                       case 0:
+                               f = current_zoomfraction;
+                               break;
+                       case 1:
+                               f = 1 - current_zoomfraction;
+                               break;
+                       case 2:
+                               f = 0;
+                               break;
+                       case 3:
+                               f = 1;
+                               break;
+               }
+               
+               switch(hud_panel_radar_rotation)
+               {
+                       case 0:
+                               teamradar_angle = view_angles_y - 90;
+                               break;
+                       default:
+                               teamradar_angle = 90 * hud_panel_radar_rotation;
+                               break;
+               }
        }
 
        vector pos, mySize;
@@ -1888,7 +1941,6 @@ void HUD_Radar(void)
        float color2;
        entity tm;
        float scale2d, normalsize, bigsize;
-       float f;
 
        teamradar_origin2d = pos + 0.5 * mySize;
        teamradar_size2d = mySize;
@@ -1898,40 +1950,13 @@ void HUD_Radar(void)
 
        teamradar_loadcvars();
 
-       switch(hud_panel_radar_zoommode)
-       {
-               default:
-               case 0:
-                       f = current_zoomfraction;
-                       break;
-               case 1:
-                       f = 1 - current_zoomfraction;
-                       break;
-               case 2:
-                       f = 0;
-                       break;
-               case 3:
-                       f = 1;
-                       break;
-       }
-
-       switch(hud_panel_radar_rotation)
-       {
-               case 0:
-                       teamradar_angle = view_angles_y - 90;
-                       break;
-               default:
-                       teamradar_angle = 90 * hud_panel_radar_rotation;
-                       break;
-       }
-
        scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
        teamradar_size2d = mySize;
 
        teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
 
        // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
-       if(hud_panel_radar_rotation == 0)
+       if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
        {
                // max-min distance must fit the radar in any rotation
                bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
@@ -1981,13 +2006,13 @@ void HUD_Radar(void)
        for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
        {
                color2 = GetPlayerColor(tm.sv_entnum);
-               //if(color == FL_SPECTATOR || color == color2)
+               //if(color == NUM_SPECTATOR || color == color2)
                        draw_teamradar_player(tm.origin, tm.angles, Team_ColorRGB(color2));
        }
        draw_teamradar_player(view_origin, view_angles, '1 1 1');
 
        drawresetcliparea();
-};
+}
 
 // Score (#7)
 //
@@ -2062,7 +2087,7 @@ void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
                // show team scores in the first line
                float score_size = mySize_x / team_count;
                for(tm = teams.sort_next; tm; tm = tm.sort_next) {
-                       if(tm.team == FL_SPECTATOR)
+                       if(tm.team == NUM_SPECTATOR)
                                continue;
                        if (tm.team == myteam)
                                drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
@@ -2078,14 +2103,14 @@ void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
        do
        for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
        {
-               if ((team_count && pl.team != tm.team) || pl.team == FL_SPECTATOR)
+               if ((team_count && pl.team != tm.team) || pl.team == NUM_SPECTATOR)
                        continue;
 
                if (i == entries-1 && !me_printed && pl != me)
                if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
                {
                        for (pl = me.sort_next; pl; pl = pl.sort_next)
-                               if (pl.team != FL_SPECTATOR)
+                               if (pl.team != NUM_SPECTATOR)
                                        break;
 
                        if (pl)
@@ -2110,7 +2135,7 @@ void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
                pos_y += fontsize_y;
                ++i;
        }
-       while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != FL_SPECTATOR || (tm = tm.sort_next)));
+       while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != NUM_SPECTATOR || (tm = tm.sort_next)));
 }
 
 void HUD_Score(void)
@@ -2120,10 +2145,8 @@ void HUD_Score(void)
                if(!autocvar_hud_panel_score) return;
                if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_SCORE;
 
-       HUD_Panel_UpdateCvars(score);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
        vector pos, mySize;
        pos = panel_pos;
@@ -2231,7 +2254,7 @@ void HUD_Score(void)
                vector score_pos, score_size; //for scores other than myteam
                if (spectatee_status == -1 || autocvar_hud_panel_score_rankings)
                {
-                       for(tm = teams.sort_next; tm, tm.team != FL_SPECTATOR; tm = tm.sort_next)
+                       for(tm = teams.sort_next; tm, tm.team != NUM_SPECTATOR; tm = tm.sort_next)
                                ++scores_count;
                        if (autocvar_hud_panel_score_rankings)
                        {
@@ -2270,7 +2293,7 @@ void HUD_Score(void)
                draw_beginBoldFont();
                row = column = 0;
                for(tm = teams.sort_next; tm; tm = tm.sort_next) {
-                       if(tm.team == FL_SPECTATOR)
+                       if(tm.team == NUM_SPECTATOR)
                                continue;
                        score = tm.(teamscores[ts_primary]);
                        if(autocvar__hud_configure)
@@ -2317,10 +2340,8 @@ void HUD_RaceTimer (void)
                if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
                if(spectatee_status == -1) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_RACETIMER;
 
-       HUD_Panel_UpdateCvars(racetimer);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
        draw_beginBoldFont();
@@ -2469,7 +2490,7 @@ float vote_prev; // previous state of vote_active to check for a change
 float vote_alpha;
 float vote_change; // "time" when vote_active changed
 
-void HUD_VoteWindow(void) 
+void HUD_Vote(void)
 {
        if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS)))
        {
@@ -2501,8 +2522,6 @@ void HUD_VoteWindow(void)
        }
        else
        {
-               hud_configure_active_panel = HUD_PANEL_VOTE;
-
                vote_yescount = 3;
                vote_nocount = 2;
                vote_needed = 4;
@@ -2523,7 +2542,7 @@ void HUD_VoteWindow(void)
        if(!vote_alpha)
                return;
 
-       HUD_Panel_UpdateCvars(vote);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
        if(uid2name_dialog)
@@ -2614,32 +2633,100 @@ void HUD_VoteWindow(void)
 
 float mod_active; // is there any active mod icon?
 
-// Clan Arena HUD modicons
-void HUD_Mod_CA(vector pos, vector mySize)
+void DrawCAItem(vector myPos, vector mySize, float aspect_ratio, float layout, float i)
 {
-       mod_active = 1; // CA should never hide the mod icons panel
-       float redalive, bluealive;
-       redalive = getstati(STAT_REDALIVE);
-       bluealive = getstati(STAT_BLUEALIVE);
+       float stat;
+       string pic;
+       vector color;
+#ifdef GMQCC
+       stat = -1;
+       pic = "";
+       color = '0 0 0';
+#endif
+       switch(i)
+       {
+               case 0:
+                       stat = getstati(STAT_REDALIVE);
+                       pic = "player_red.tga";
+                       color = '1 0 0';
+                       break;
+               case 1:
+                       stat = getstati(STAT_BLUEALIVE);
+                       pic = "player_blue.tga";
+                       color = '0 0 1';
+                       break;
+               case 2:
+                       stat = getstati(STAT_YELLOWALIVE);
+                       pic = "player_yellow.tga";
+                       color = '1 1 0';
+                       break;
+               default:
+               case 3:
+                       stat = getstati(STAT_PINKALIVE);
+                       pic = "player_pink.tga";
+                       color = '1 0 1';
+                       break;
+       }
 
-       vector redpos, bluepos;
-       if(mySize_x > mySize_y)
+       if(mySize_x/mySize_y > aspect_ratio)
        {
-               redpos = pos;
-               bluepos = pos + eY * 0.5 * mySize_y;
-               drawpic_aspect_skin(redpos, "player_red.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-               drawstring_aspect(redpos + eX * 0.5 * mySize_x, ftos(redalive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-               drawpic_aspect_skin(bluepos, "player_blue.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-               drawstring_aspect(bluepos + eX * 0.5 * mySize_x, ftos(bluealive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+               i = aspect_ratio * mySize_y;
+               myPos_x = myPos_x + (mySize_x - i) / 2;
+               mySize_x = i;
        }
        else
        {
-               redpos = pos;
-               bluepos = pos + eY * 0.5 * mySize_y;
-               drawpic_aspect_skin(redpos, "player_red.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-               drawstring_aspect(redpos + eY * 0.3 * mySize_y, ftos(redalive), eX * mySize_x + eY * 0.2 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-               drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-               drawstring_aspect(bluepos + eY * 0.3 * mySize_y, ftos(bluealive), eX * mySize_x + eY * 0.2 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+               i = 1/aspect_ratio * mySize_x;
+               myPos_y = myPos_y + (mySize_y - i) / 2;
+               mySize_y = i;
+       }
+
+       if(layout)
+       {
+               drawpic_aspect_skin(myPos, pic, eX * 0.7 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawstring_aspect(myPos + eX * 0.7 * mySize_x, ftos(stat), eX * 0.3 * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
+       }
+       else
+               drawstring_aspect(myPos, ftos(stat), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
+}
+
+// Clan Arena and Freeze Tag HUD modicons
+void HUD_Mod_CA(vector myPos, vector mySize)
+{
+       mod_active = 1; // required in each mod function that always shows something
+       entity tm;
+       float teams_count = 0;
+       for(tm = teams.sort_next; tm; tm = tm.sort_next)
+               if(tm.team != NUM_SPECTATOR)
+                       ++teams_count;
+
+       float layout;
+       if(gametype == MAPINFO_TYPE_CA)
+               layout = autocvar_hud_panel_modicons_ca_layout;
+       else //if(gametype == MAPINFO_TYPE_FREEZETAG)
+               layout = autocvar_hud_panel_modicons_freezetag_layout;
+       float rows, columns, aspect_ratio;
+       rows = mySize_y/mySize_x;
+       aspect_ratio = (layout) ? 2 : 1;
+       rows = bound(1, floor((sqrt((4 * aspect_ratio * teams_count + rows) * rows) + rows + 0.5) / 2), teams_count);
+       columns = ceil(teams_count/rows);
+
+       int i;
+       float row = 0, column = 0;
+       vector pos, itemSize;
+       itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
+       for(i=0; i<teams_count; ++i)
+       {
+               pos = myPos + eX * column * itemSize_x + eY * row * itemSize_y;
+
+               DrawCAItem(pos, itemSize, aspect_ratio, layout, i);
+
+               ++row;
+               if(row >= rows)
+               {
+                       row = 0;
+                       ++column;
+               }
        }
 }
 
@@ -2713,7 +2800,7 @@ void HUD_Mod_CTF(vector pos, vector mySize)
                case 2: red_icon = "flag_red_lost"; break;
                case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
                default:
-                       if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_2))
+                       if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_2))
                                red_icon = "flag_red_shielded";
                        else
                                red_icon = string_null;
@@ -2726,7 +2813,7 @@ void HUD_Mod_CTF(vector pos, vector mySize)
                default:
                        if(redflag == 3)
                                red_icon_prevstatus = "flag_red_carrying"; // make it more visible
-                       else if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_2))
+                       else if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_2))
                                red_icon_prevstatus = "flag_red_shielded";
                        else
                                red_icon_prevstatus = string_null;
@@ -2741,7 +2828,7 @@ void HUD_Mod_CTF(vector pos, vector mySize)
                case 2: blue_icon = "flag_blue_lost"; break;
                case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
                default:
-                       if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_1))
+                       if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_1))
                                blue_icon = "flag_blue_shielded";
                        else
                                blue_icon = string_null;
@@ -2754,7 +2841,7 @@ void HUD_Mod_CTF(vector pos, vector mySize)
                default:
                        if(blueflag == 3)
                                blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
-                       else if((stat_items & IT_CTF_SHIELDED) && (myteam == FL_TEAM_1))
+                       else if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_1))
                                blue_icon_prevstatus = "flag_blue_shielded";
                        else
                                blue_icon_prevstatus = string_null;
@@ -2762,7 +2849,7 @@ void HUD_Mod_CTF(vector pos, vector mySize)
        }
 
        if(mySize_x > mySize_y) {
-               if (myteam == FL_TEAM_1) { // always draw own flag on left
+               if (myteam == NUM_TEAM_1) { // always draw own flag on left
                        redflag_pos = pos;
                        blueflag_pos = pos + eX * 0.5 * mySize_x;
                } else {
@@ -2771,7 +2858,7 @@ void HUD_Mod_CTF(vector pos, vector mySize)
                }
                flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
        } else {
-               if (myteam == FL_TEAM_1) { // always draw own flag on left
+               if (myteam == NUM_TEAM_1) { // always draw own flag on left
                        redflag_pos = pos;
                        blueflag_pos = pos + eY * 0.5 * mySize_y;
                } else {
@@ -2885,16 +2972,16 @@ void HUD_Mod_KH(vector pos, vector mySize)
                {
                        switch(keyteam)
                        {
-                               case FL_TEAM_1:
+                               case NUM_TEAM_1:
                                        drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% theAlpha key
                                        break;
-                               case FL_TEAM_2:
+                               case NUM_TEAM_2:
                                        drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% theAlpha key
                                        break;
-                               case FL_TEAM_3:
+                               case NUM_TEAM_3:
                                        drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% theAlpha key
                                        break;
-                               case FL_TEAM_4:
+                               case NUM_TEAM_4:
                                        drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% theAlpha key
                                        break;
                                default:
@@ -3241,7 +3328,7 @@ void HUD_Mod_Dom(vector myPos, vector mySize)
        entity tm;
        float teams_count = 0;
        for(tm = teams.sort_next; tm; tm = tm.sort_next)
-               if(tm.team != FL_SPECTATOR)
+               if(tm.team != NUM_SPECTATOR)
                        ++teams_count;
 
        float layout = autocvar_hud_panel_modicons_dom_layout;
@@ -3253,11 +3340,11 @@ void HUD_Mod_Dom(vector myPos, vector mySize)
 
        int i;
        float row = 0, column = 0;
+       vector pos, itemSize;
+       itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
        for(i=0; i<teams_count; ++i)
        {
-               vector pos, itemSize;
-               pos = myPos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
-               itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
+               pos = myPos + eX * column * itemSize_x + eY * row * itemSize_y;
 
                DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
 
@@ -3281,10 +3368,8 @@ void HUD_ModIcons(void)
                if(!autocvar_hud_panel_modicons) return;
                if (gametype != MAPINFO_TYPE_CTF && gametype != MAPINFO_TYPE_KEYHUNT && gametype != MAPINFO_TYPE_NEXBALL && gametype != MAPINFO_TYPE_CTS && gametype != MAPINFO_TYPE_RACE && gametype != MAPINFO_TYPE_CA && gametype != MAPINFO_TYPE_FREEZETAG && gametype != MAPINFO_TYPE_KEEPAWAY && gametype != MAPINFO_TYPE_DOMINATION) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_MODICONS;
 
-       HUD_Panel_UpdateCvars(modicons);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
        draw_beginBoldFont();
@@ -3333,18 +3418,15 @@ void HUD_ModIcons(void)
 
 // Draw pressed keys (#11)
 //
-void HUD_DrawPressedKeys(void)
+void HUD_PressedKeys(void)
 {
        if(!autocvar__hud_configure)
        {
                if(!autocvar_hud_panel_pressedkeys) return;
                if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS;
 
-
-       HUD_Panel_UpdateCvars(pressedkeys);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
        vector pos, mySize;
        pos = panel_pos;
@@ -3415,10 +3497,8 @@ void HUD_Chat(void)
                if(autocvar__con_chat_maximized)
                        if(!hud_draw_maximized) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_CHAT;
 
-       HUD_Panel_UpdateCvars(chat);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
        if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
@@ -3491,10 +3571,8 @@ void HUD_EngineInfo(void)
        {
                if(!autocvar_hud_panel_engineinfo) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_ENGINEINFO;
 
-       HUD_Panel_UpdateCvars(engineinfo);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
        vector pos, mySize;
        pos = panel_pos;
@@ -3554,10 +3632,8 @@ void HUD_InfoMessages(void)
        {
                if(!autocvar_hud_panel_infomessages) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_INFOMESSAGES;
 
-       HUD_Panel_UpdateCvars(infomessages);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
        vector pos, mySize;
        pos = panel_pos;
@@ -3617,7 +3693,7 @@ void HUD_InfoMessages(void)
                        if(spectatee_status == -1)
                                s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
                        else
-                               s = sprintf(_("^1Press ^3%s^1 for another player"), getcommandkey("primary fire", "+fire"));
+                               s = sprintf(_("^1Press ^3%s^1 or ^3%s^1 for next or previous player"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
                        drawInfoMessage(s)
 
                        if(spectatee_status == -1)
@@ -3700,7 +3776,7 @@ void HUD_InfoMessages(void)
                        {
                                for(; tm.sort_next; tm = tm.sort_next)
                                {
-                                       if(!tm.team_size || tm.team == FL_SPECTATOR)
+                                       if(!tm.team_size || tm.team == NUM_SPECTATOR)
                                                continue;
                                        if(!ts_min) ts_min = tm.team_size;
                                        else ts_min = min(ts_min, tm.team_size);
@@ -3712,7 +3788,7 @@ void HUD_InfoMessages(void)
                                        s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
                                        tm = GetTeam(myteam, false);
                                        if (tm)
-                                       if (tm.team != FL_SPECTATOR)
+                                       if (tm.team != NUM_SPECTATOR)
                                        if (tm.team_size == ts_max)
                                                s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
                                        drawInfoMessage(s)
@@ -3745,10 +3821,8 @@ void HUD_Physics(void)
                if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
                if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_PHYSICS;
 
-       HUD_Panel_UpdateCvars(physics);
+       HUD_Panel_UpdateCvars();
        HUD_Panel_ApplyFadeAlpha();
 
        draw_beginBoldFont();
@@ -4024,6 +4098,7 @@ float centerprint_showing;
 
 void centerprint_generic(float new_id, string strMessage, float duration, float countdown_num)
 {
+       //print(sprintf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num));
        float i, j;
 
        if(strMessage == "" && new_id == 0)
@@ -4083,7 +4158,10 @@ void centerprint_generic(float new_id, string strMessage, float duration, float
        centerprint_messages[j] = strzone(strMessage);
        centerprint_msgID[j] = new_id;
        if (duration < 0)
+       {
                centerprint_time[j] = -1;
+               centerprint_expire_time[j] = time;
+       }
        else
        {
                if(duration == 0)
@@ -4124,8 +4202,6 @@ void HUD_CenterPrint (void)
        }
        else
        {
-               hud_configure_active_panel = HUD_PANEL_CENTERPRINT;
-
                if (!hud_configure_prev)
                        reset_centerprint_messages();
                if (time > hud_configure_cp_generation_time)
@@ -4142,7 +4218,7 @@ void HUD_CenterPrint (void)
                }
        }
 
-       HUD_Panel_UpdateCvars(centerprint);
+       HUD_Panel_UpdateCvars();
 
        // this panel doesn't fade when showing the scoreboard
        if(autocvar__menu_alpha)
@@ -4184,7 +4260,7 @@ void HUD_CenterPrint (void)
        fontsize = '1 1 0' * height;
        entries = bound(1, floor(panel_size_y/height), CENTERPRINT_MAX_ENTRIES);
 
-       float i, j, k, n;
+       float i, j, k, n, g;
        float a, sz, align, current_msg_pos_y = 0, msg_size;
        vector pos;
        string ts;
@@ -4195,7 +4271,7 @@ void HUD_CenterPrint (void)
        if (autocvar_hud_panel_centerprint_flip)
                pos_y += panel_size_y;
        align = bound(0, autocvar_hud_panel_centerprint_align, 1);
-       for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
+       for (g=0, i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
        {
                if (j == CENTERPRINT_MAX_MSGS)
                        j = 0;
@@ -4208,14 +4284,17 @@ void HUD_CenterPrint (void)
                                        continue;
                                centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
                        }
-                       else
+                       else if(centerprint_time[j] != -1)
                                continue;
                }
-               
+
+
                // fade the centerprint_hud in/out 
-               if (centerprint_time[j] < 0 || centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time)
+               if(centerprint_time[j] < 0)
+                       a = bound(0, (time - centerprint_expire_time[j]) / max(0.0001, autocvar_hud_panel_centerprint_fade_in), 1);
+               else if(centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time)
                        a = bound(0, (time - (centerprint_expire_time[j] - centerprint_time[j])) / max(0.0001, autocvar_hud_panel_centerprint_fade_in), 1);
-               else if (centerprint_expire_time[j] > time)
+               else if(centerprint_expire_time[j] > time)
                        a = (centerprint_expire_time[j] - time) / max(0.0001, autocvar_hud_panel_centerprint_fade_out);
                else
                        a = 0;
@@ -4226,8 +4305,8 @@ void HUD_CenterPrint (void)
                // also fade it based on positioning
                if(autocvar_hud_panel_centerprint_fade_subsequent)
                {
-                       a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passone_minalpha, (1 - (i / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passone))), 1); // pass one: all messages after the first have half theAlpha
-                       a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passtwo_minalpha, (1 - (i / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passtwo))), 1); // pass two: after that, gradually lower theAlpha even more for each message
+                       a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passone_minalpha, (1 - (g / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passone))), 1); // pass one: all messages after the first have half theAlpha
+                       a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passtwo_minalpha, (1 - (g / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passtwo))), 1); // pass two: after that, gradually lower theAlpha even more for each message
                }
                
                // finally set the size based on the new theAlpha from subsequent fading
@@ -4275,6 +4354,9 @@ void HUD_CenterPrint (void)
                                        pos_y += fontsize_y * CENTERPRINT_SPACING/2;
                        }
                }
+
+               ++g; // move next position number up 
+               
                msg_size = pos_y - msg_size;
                if (autocvar_hud_panel_centerprint_flip)
                {
@@ -4324,44 +4406,6 @@ void HUD_Reset (void)
                HUD_Mod_CTF_Reset();
 }
 
-#define HUD_DrawPanel(id)\
-switch (id) {\
-       case (HUD_PANEL_RADAR):\
-               HUD_Radar(); break;\
-       case (HUD_PANEL_WEAPONS):\
-               HUD_Weapons(); break;\
-       case (HUD_PANEL_AMMO):\
-               HUD_Ammo(); break;\
-       case (HUD_PANEL_POWERUPS):\
-               HUD_Powerups(); break;\
-       case (HUD_PANEL_HEALTHARMOR):\
-               HUD_HealthArmor(); break;\
-       case (HUD_PANEL_NOTIFY):\
-               HUD_Notify(); break;\
-       case (HUD_PANEL_TIMER):\
-               HUD_Timer(); break;\
-       case (HUD_PANEL_SCORE):\
-               HUD_Score(); break;\
-       case (HUD_PANEL_RACETIMER):\
-               HUD_RaceTimer(); break;\
-       case (HUD_PANEL_VOTE):\
-               HUD_VoteWindow(); break;\
-       case (HUD_PANEL_MODICONS):\
-               HUD_ModIcons(); break;\
-       case (HUD_PANEL_PRESSEDKEYS):\
-               HUD_DrawPressedKeys(); break;\
-       case (HUD_PANEL_CHAT):\
-               HUD_Chat(); break;\
-       case (HUD_PANEL_ENGINEINFO):\
-               HUD_EngineInfo(); break;\
-       case (HUD_PANEL_INFOMESSAGES):\
-               HUD_InfoMessages(); break;\
-       case (HUD_PANEL_PHYSICS):\
-               HUD_Physics(); break;\
-       case (HUD_PANEL_CENTERPRINT):\
-               HUD_CenterPrint(); break;\
-} ENDS_WITH_CURLY_BRACE
-
 void HUD_Main (void)
 {
        float i;
@@ -4391,7 +4435,7 @@ void HUD_Main (void)
        // they must call HUD_Panel_ApplyFadeAlpha(); only when showing the menu
        if(scoreboard_fade_alpha == 1)
        {
-               HUD_CenterPrint();
+               (panel = HUD_PANEL(CENTERPRINT)).panel_draw();
                return;
        }
 
@@ -4440,8 +4484,10 @@ void HUD_Main (void)
                vector color;
                float hud_dock_color_team = autocvar_hud_dock_color_team;
                if((teamplay) && hud_dock_color_team) {
-                       f = stof(getplayerkeyvalue(current_player - 1, "colors"));
-                       color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
+                       if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
+                               color = '1 0 0' * hud_dock_color_team;
+                       else
+                               color = myteamcolors * hud_dock_color_team;
                }
                else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
                        color = '1 0 0' * hud_dock_color_team;
@@ -4516,31 +4562,35 @@ void HUD_Main (void)
        hud_draw_maximized = 0;
        // draw panels in order specified by panel_order array
        for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
-               HUD_DrawPanel(panel_order[i]);
+               (panel = hud_panel[panel_order[i]]).panel_draw();
 
        hud_draw_maximized = 1; // panels that may be maximized must check this var
        // draw maximized panels on top
        if(hud_panel_radar_maximized)
-               HUD_Radar();
+               (panel = HUD_PANEL(RADAR)).panel_draw();
        if(autocvar__con_chat_maximized)
-               HUD_Chat();
+               (panel = HUD_PANEL(CHAT)).panel_draw();
 
        if(autocvar__hud_configure)
        {
-               if(tab_panel != -1)
+               if(tab_panel)
                {
-                       HUD_Panel_UpdatePosSizeForId(tab_panel)
+                       panel = tab_panel;
+                       HUD_Panel_UpdatePosSize()
                        drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
                }
-               if(highlightedPanel != -1)
+               if(highlightedPanel)
                {
-                       HUD_Panel_UpdatePosSizeForId(highlightedPanel);
+                       panel = highlightedPanel;
+                       HUD_Panel_UpdatePosSize()
                        HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha));
                }
                if(!hud_configure_prev || hud_configure_prev == -1)
                {
                        if(autocvar_hud_cursormode) { setcursormode(1); }
                        hudShiftState = 0;
+                       for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
+                               hud_panel[panel_order[i]].update_time = time;
                }
        }
        else if (hud_configure_prev && autocvar_hud_cursormode)