// titles for chosen songs.
unsigned width[16], num_scores;
unsigned max_num_width = my_draw_text("8888", NULL, 22.0);
- unsigned mode;
+ unsigned mode, sumwidth;
for (mode = 0; mode < 2; ++mode) {
for (unsigned i = 0; i < 16; ++i)
width[i] = 0;
width[num_scores + 2] = my_draw_text("Rank", NULL, 12.0);
// if we're at long titles and that works, don't try the short ones
- if (mode == 0) {
- unsigned sumwidth = 0;
- for (unsigned i = 0; i <= num_scores + 2; ++i)
- sumwidth += width[i] + 20;
+ sumwidth = 0;
- if (sumwidth < 800)
+ for (unsigned i = 0; i <= num_scores + 2; ++i)
+ sumwidth += width[i] + 20;
+
+ if (sumwidth < 780)
+ break;
+ }
+
+ /*
+ * If we have space to go, distribute as much as we can to the chosen song column, so we won't have
+ * total and rank jumping around.
+ */
+ if (sumwidth < 780) {
+ int first_chosen_col = -1;
+ unsigned col = 1;
+
+ for (std::vector<Score>::const_iterator i = group.players[0].scores.begin(); i != group.players[0].scores.end(); ++i, ++col) {
+ if (i->chosen) {
+ first_chosen_col = col;
break;
+ }
+ }
+
+ if (first_chosen_col != -1) {
+ printf("first_chosen_col=%u\n", first_chosen_col);
+ width[first_chosen_col] += 780 - sumwidth;
}
}
* <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. */
}
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;