From 13ed6ca4807f938eba70592b2cb728cd3b632115 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 20 Feb 2005 16:00:09 +0000 Subject: [PATCH] Add preliminary "needs to qualify/win" text. 14:00-17:00 --- bigscreen/groupscreen.cpp | 77 ++++++++++++++++++++++++++++++++++++++- bigscreen/widestring.cpp | 10 +++++ bigscreen/widestring.h | 2 + 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/bigscreen/groupscreen.cpp b/bigscreen/groupscreen.cpp index 64bf7b9..7062812 100644 --- a/bigscreen/groupscreen.cpp +++ b/bigscreen/groupscreen.cpp @@ -257,8 +257,9 @@ void GroupScreen::draw(unsigned char *buf) * * * High score: by at - * Needs to (lead/win): + * Needs to lead: * Needs to secure qualification: + * Needs to win group: */ /* 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; diff --git a/bigscreen/widestring.cpp b/bigscreen/widestring.cpp index 9193586..4b67ec7 100644 --- a/bigscreen/widestring.cpp +++ b/bigscreen/widestring.cpp @@ -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) { diff --git a/bigscreen/widestring.h b/bigscreen/widestring.h index 437428c..67ffdbb 100644 --- a/bigscreen/widestring.h +++ b/bigscreen/widestring.h @@ -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); }; -- 2.39.2