Add preliminary "needs to qualify/win" text.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sun, 20 Feb 2005 16:00:09 +0000 (16:00 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sun, 20 Feb 2005 16:00:09 +0000 (16:00 +0000)
14:00-17:00

bigscreen/groupscreen.cpp
bigscreen/widestring.cpp
bigscreen/widestring.h

index 64bf7b9..7062812 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;
index 9193586..4b67ec7 100644 (file)
@@ -16,6 +16,16 @@ widestring::widestring(const char *from)
        *this = from;
 }
 
+widestring::widestring(const std::string &from)
+{
+       *this = from.c_str();
+}
+
+widestring::widestring(const std::wstring &from)
+       : std::wstring(from)
+{
+}
+
 void widestring::operator= (const char *from)
 {
        if (!iconv_initialized) {
index 437428c..67ffdbb 100644 (file)
@@ -9,6 +9,8 @@ class widestring : public std::wstring
 public:
        widestring();
        widestring(const char *from);
+       widestring(const std::string &from);
+       widestring(const std::wstring &from);
        void operator= (const char *from);
 };