]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sbar.c
esteel's patch used C99 lazy variable declaration, fixed
[xonotic/darkplaces.git] / sbar.c
diff --git a/sbar.c b/sbar.c
index 59941a5ffb7eb7f69ece142f2faeb1dfa38e2afb..16513a97b9d54e5e5432ce03639a69f25aeb7fbc 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -147,7 +147,10 @@ void sbar_start(void)
 
        numsbarpics = 0;
 
-       if (gamemode == GAME_SOM)
+       if (gamemode == GAME_NETHERWORLD)
+       {
+       }
+       else if (gamemode == GAME_SOM)
        {
                sb_disc = Sbar_NewPic("gfx/disc");
 
@@ -468,6 +471,13 @@ void Sbar_DrawXNum (int x, int y, int num, int digits, int lettersize, float r,
 //=============================================================================
 
 
+int Sbar_IsTeammatch()
+{
+       // currently only nexuiz uses the team score board
+       return ((gamemode == GAME_NEXUIZ)
+               && (teamplay.integer > 0));
+}
+
 /*
 ===============
 Sbar_SortFrags
@@ -475,11 +485,14 @@ Sbar_SortFrags
 */
 static int fragsort[MAX_SCOREBOARD];
 static int scoreboardlines;
+static scoreboard_t teams[MAX_SCOREBOARD];
+static int teamsort[MAX_SCOREBOARD];
+static int teamlines;
 void Sbar_SortFrags (void)
 {
-       int             i, j, k;
+       int i, j, k, color;
 
-// sort by frags
+       // sort by frags
        scoreboardlines = 0;
        for (i=0 ; i<cl.maxclients ; i++)
        {
@@ -498,6 +511,61 @@ void Sbar_SortFrags (void)
                                fragsort[j] = fragsort[j+1];
                                fragsort[j+1] = k;
                        }
+
+       teamlines = 0;
+       if (Sbar_IsTeammatch ())
+       {
+               // now sort players by teams.
+               for (i=0 ; i<scoreboardlines ; i++)
+               {
+                       for (j=0 ; j<scoreboardlines-1-i ; j++)
+                       {
+                               if (cl.scores[fragsort[j]].colors < cl.scores[fragsort[j+1]].colors)
+                               {
+                                       k = fragsort[j];
+                                       fragsort[j] = fragsort[j+1];
+                                       fragsort[j+1] = k;
+                               }
+                       }
+               }
+
+               // calculate team scores
+               color = -1;
+               for (i=0 ; i<scoreboardlines ; i++)
+               {
+                       if (color != cl.scores[fragsort[i]].colors)
+                       {
+                               color = cl.scores[fragsort[i]].colors;
+                               teamlines++;
+                               strcpy(teams[teamlines-1].name, "Total Team Score");
+                               teams[teamlines-1].frags = 0;
+                               teams[teamlines-1].colors = cl.scores[fragsort[i]].colors;
+                       }
+
+                       if (cl.scores[fragsort[i]].frags != -666)
+                       {
+                               // do not add spedcators
+                               // (ugly hack for nexuiz)
+                               teams[teamlines-1].frags += cl.scores[fragsort[i]].frags;
+                       }
+               }
+
+               // now sort teams by scores.
+               for (i=0 ; i<teamlines ; i++)
+                       teamsort[i] = i;
+               for (i=0 ; i<teamlines ; i++)
+               {
+                       for (j=0 ; j<teamlines-1-i ; j++)
+                       {
+                               if (teams[teamsort[j]].frags < teams[teamsort[j+1]].frags)
+                               {
+                                       k = teamsort[j];
+                                       teamsort[j] = teamsort[j+1];
+                                       teamsort[j+1] = k;
+                               }
+                       }
+               }
+       }
 }
 
 /*
@@ -724,7 +792,7 @@ void Sbar_DrawFrags (void)
        int i, k, l, x, f;
        char num[12];
        scoreboard_t *s;
-       qbyte *c;
+       unsigned char *c;
 
        Sbar_SortFrags ();
 
@@ -739,9 +807,9 @@ void Sbar_DrawFrags (void)
                s = &cl.scores[k];
 
                // draw background
-               c = (qbyte *)&palette_complete[(s->colors & 0xf0) + 8];
+               c = (unsigned char *)&palette_complete[(s->colors & 0xf0) + 8];
                DrawQ_Fill (sbar_x + x + 10, sbar_y     - 23, 28, 4, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
-               c = (qbyte *)&palette_complete[((s->colors & 15)<<4) + 8];
+               c = (unsigned char *)&palette_complete[((s->colors & 15)<<4) + 8];
                DrawQ_Fill (sbar_x + x + 10, sbar_y + 4 - 23, 28, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
 
                // draw number
@@ -778,14 +846,14 @@ void Sbar_DrawFace (void)
        {
                char num[12];
                scoreboard_t *s;
-               qbyte *c;
+               unsigned char *c;
 
                s = &cl.scores[cl.viewentity - 1];
                // draw background
                Sbar_DrawPic (112, 0, rsb_teambord);
-               c = (qbyte *)&palette_complete[(s->colors & 0xf0) + 8];
+               c = (unsigned char *)&palette_complete[(s->colors & 0xf0) + 8];
                DrawQ_Fill (sbar_x + 113, vid_conheight.integer-SBAR_HEIGHT+3, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
-               c = (qbyte *)&palette_complete[((s->colors & 15)<<4) + 8];
+               c = (unsigned char *)&palette_complete[((s->colors & 15)<<4) + 8];
                DrawQ_Fill (sbar_x + 113, vid_conheight.integer-SBAR_HEIGHT+12, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
 
                // draw number
@@ -967,7 +1035,10 @@ void Sbar_Draw (void)
                return;
        }
 
-       if (gamemode == GAME_SOM)
+       if (gamemode == GAME_NETHERWORLD)
+       {
+       }
+       else if (gamemode == GAME_SOM)
        {
                if (sb_showscores || (cl.stats[STAT_HEALTH] <= 0 && cl_deathscoreboard.integer))
                        Sbar_DrawScoreboard ();
@@ -1289,11 +1360,11 @@ Sbar_DeathmatchOverlay
 */
 float Sbar_PrintScoreboardItem(scoreboard_t *s, float x, float y)
 {
-       qbyte *c;
+       unsigned char *c;
        // draw colors behind score
-       c = (qbyte *)&palette_complete[(s->colors & 0xf0) + 8];
+       c = (unsigned char *)&palette_complete[(s->colors & 0xf0) + 8];
        DrawQ_Fill(x + 8, y+1, 32, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
-       c = (qbyte *)&palette_complete[((s->colors & 15)<<4) + 8];
+       c = (unsigned char *)&palette_complete[((s->colors & 15)<<4) + 8];
        DrawQ_Fill(x + 8, y+4, 32, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
        // print the text
        //DrawQ_String(x, y, va("%c%4i %s", (s - cl.scores) == cl.playerentity - 1 ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0);
@@ -1315,6 +1386,15 @@ void Sbar_DeathmatchOverlay (void)
        // draw the text
        x = (vid_conwidth.integer - (6 + 15) * 8) / 2;
        y = 40;
+
+       if (Sbar_IsTeammatch ())
+       {
+               // show team scores first
+               for (i = 0;i < teamlines && y < vid_conheight.integer;i++)
+                       y += Sbar_PrintScoreboardItem((teams + teamsort[i]), x, y);
+               y += 5;
+       }
+
        for (i = 0;i < scoreboardlines && y < vid_conheight.integer;i++)
                y += Sbar_PrintScoreboardItem(cl.scores + fragsort[i], x, y);
 }