summaryrefslogtreecommitdiff
path: root/web/web_scoreboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/web_scoreboard.c')
-rw-r--r--web/web_scoreboard.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c
index bc1a9d0..1b3660d 100644
--- a/web/web_scoreboard.c
+++ b/web/web_scoreboard.c
@@ -83,25 +83,29 @@ void scoreboard_flush_player_info(int pn)
if (buffered_str_changed(buffered_info[pn-1].name,
flushed_info[pn-1].name)) {
strcpy(sel + len, "name");
- EM_ASM({elemSetContent($0, $1)}, sel, buffered_info[pn-1].name);
+ EM_ASM({elemSetContent($0, $1)},
+ sel, buffered_info[pn-1].name);
}
if (buffered_str_changed(buffered_info[pn-1].rem,
flushed_info[pn-1].rem)) {
strcpy(sel + len, "rem");
- EM_ASM({elemSetContent($0, $1)}, sel, buffered_info[pn-1].rem);
+ EM_ASM({elemSetContent($0, $1)},
+ sel, buffered_info[pn-1].rem);
}
if (buffered_str_changed(buffered_info[pn-1].sugg,
flushed_info[pn-1].sugg)) {
strcpy(sel + len, "sugg");
- EM_ASM({elemSetContent($0, $1)}, sel, buffered_info[pn-1].sugg);
+ EM_ASM({elemSetContent($0, $1)},
+ sel, buffered_info[pn-1].sugg);
}
if (buffered_str_changed(buffered_info[pn-1].avg,
flushed_info[pn-1].avg)) {
strcpy(sel + len, "avg");
- EM_ASM({elemSetContent($0, $1)}, sel, buffered_info[pn-1].avg);
+ EM_ASM({elemSetContent($0, $1)},
+ sel, buffered_info[pn-1].avg);
}
free_flushed_str(flushed_info[pn-1].name, buffered_info[pn-1].name);
@@ -139,14 +143,20 @@ void update_player_sugg(int pn, int rem)
scoreboard_set_player_sugg(pn, str);
}
+static double calc_avg(struct leg *l, int n_darts) {
+ if (!l->n_visits)
+ return 0;
+
+ if (l->rem > 0)
+ return ((double)(l->start - l->rem) / l->n_visits);
+
+ return ((double)l->start / (((l->n_visits - 1) * 3) + n_darts) * 3);
+}
+
void update_player_avg(int pn, int n_darts)
{
struct leg *l = state->legs[pn-1];
- scoreboard_set_player_avg(pn,
- l->n_visits ?
- (l->rem > 0 ? ((double)(l->start - l->rem) / l->n_visits) :
- ((double)l->start / (((l->n_visits - 1) * 3) + n_darts) * 3)) :
- 0);
+ scoreboard_set_player_avg(pn, calc_avg(l, n_darts));
}
void update_player_rem(int pn, int rem)
@@ -238,7 +248,8 @@ void draw_visits()
strcpy(buf, "… ");
for (int j = 0; j < v->n_darts; ++j) {
char *n = segment_name(v->darts[j]);
- sprintf(buf + strlen(buf), j == 0 ? "%4s" : " %4s", n); // FIXME
+ sprintf(buf + strlen(buf),
+ j == 0 ? "%4s" : " %4s", n); // FIXME
free(n);
}
elemv[elemc++] = gen_div(buf, "visit-col6");