]> git.sesse.net Git - ccbs/blobdiff - bigscreen/groupscreen.cpp
Add preliminary "needs to qualify/win" text.
[ccbs] / bigscreen / groupscreen.cpp
index 64bf7b9f44986072bf806a896dd3e5bfe00092ce..706281215112adc4bbd19b40a33d5eb0b578be5a 100644 (file)
@@ -257,8 +257,9 @@ void GroupScreen::draw(unsigned char *buf)
         * <player>
         * <song>
         * High score: <hs> by <hsplayer> at <hsevent>
-        * Needs to (lead/win): <leadscore>
+        * Needs to lead: <leadscore>
         * Needs to secure qualification: <qualscore>
+        * Needs to win group: <winscore>
         */
        
        /* Find the first player with the fewest songs played. */
@@ -305,7 +306,79 @@ void GroupScreen::draw(unsigned char *buf)
        }
 
        if (next_song != NULL) {
-               printf("Next: player %u\n", next_player->id);
+               widestring text = widestring("Next player: ") + next_player->nick;
+               unsigned this_width = my_draw_text(text, NULL, 24.0);
+               my_draw_text(text, buf, 24.0, 400 - this_width/2, 450);
+
+               if (next_song->song.id != -1) {
+                       this_width = my_draw_text(next_song->song.title, NULL, 20.0);
+                       my_draw_text(next_song->song.title, buf, 20.0, 400 - this_width/2, 487);
+
+                       // fetch the high score later
+                       text = widestring("High score: ") + widestring(pqxx::to_string(1234)) +
+                               widestring(", by dufF in Challenge Cup 1, 2004");
+                       this_width = my_draw_text(text, NULL, 16.0);
+                       my_draw_text(text, buf, 16.0, 400 - this_width/2, 517);
+               }
+
+               // only show lead/win/qualify for the last song
+               if (min_played_songs == num_scores - 1) {
+                       /*
+                        * Find out how much we need to lead, how much we need to be guaranteed
+                        * to win the group, and how much we need to secure qualification. (FIXME:
+                        * do the last one :-) )
+                        */
+                       
+                       // find the best score we can get
+                       unsigned max_score_this_song;
+                       if (next_song->song.id != -1) {
+                               // random song, or we know what song the player picked
+                               conn.perform(FetchMaxScoreForSong(tournament, next_song->song.id, &max_score_this_song));
+                       } else {
+                               conn.perform(FetchMaxScoreForPlayer(tournament, next_player->id, round, &max_score_this_song));
+                       }
+
+                       unsigned y = 540;
+                       
+                       // see what score this player must beat to lead
+                       unsigned lead_beat = 0, win_beat = 0, qualify_beat = 0;
+                       for (unsigned i = 0; i < group.players.size(); ++i) {
+                               if (group.players[i].id == next_player->id)
+                                       continue;
+                               
+                               lead_beat = std::max(lead_beat, group.players[i].total);
+                       }
+
+                       // find the best max score among the others
+                       for (unsigned i = 0; i < group.players.size(); ++i) {
+                               if (group.players[i].id == next_player->id)
+                                       continue;
+
+                               win_beat = std::max(win_beat, max_score[i]);
+                       }
+
+                       // print out the lines we can attain
+                       if (next_player->total + max_score_this_song > lead_beat) {
+                               int lead_need = std::max(lead_beat - next_player->total + 1, 0U);
+                               
+                               text = widestring("Needs to lead: ") + widestring(pqxx::to_string(lead_need));
+                               this_width = my_draw_text(text, NULL, 22.0);
+                               my_draw_text(text, buf, 22.0, 400 - this_width/2, y);
+
+                               y += 30;
+                       }
+                       
+                       if (next_player->total + max_score_this_song > win_beat) {
+                               int win_need = std::max(win_beat - next_player->total + 1, 0U);
+                               
+                               text = widestring("Needs to win: ") + widestring(pqxx::to_string(win_need));
+
+                               this_width = my_draw_text(text, NULL, 22.0);
+                               my_draw_text(text, buf, 22.0, 400 - this_width/2, y);
+
+                               y += 30;
+                       }
+               }
        }
        
        valid = true;