summaryrefslogtreecommitdiff
path: root/dartbot.c
diff options
context:
space:
mode:
Diffstat (limited to 'dartbot.c')
-rw-r--r--dartbot.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/dartbot.c b/dartbot.c
index 8348d6c..992ff0e 100644
--- a/dartbot.c
+++ b/dartbot.c
@@ -36,6 +36,23 @@
#define GEN_RING_STRING(X, D) #X,
#define GEN_RING_OUTER_DIST(X, D) D,
+#define FOREACH_COLOUR(M) \
+ M(140, 82, 0) \
+ M(100, 154, 0) \
+ M(60, 226, 0) \
+ M(40, 214, 0) \
+ M(20, 202, 0) \
+ M(0, 196, 0) \
+ M(DARTS, 235, 0) \
+ M(VISIT, 244, 0)
+#define GEN_COLOUR_ENUM(X, FG, BG) C_ ## X,
+#define GEN_COLOUR_INIT_PAIR(X, FG, BG) init_pair(C_ ## X, FG, BG);
+
+enum colour {
+ C_DEFAULT, // need rest to start at 1
+ FOREACH_COLOUR(GEN_COLOUR_ENUM)
+};
+
int SECTORS[] = { 20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7,
16, 8, 11, 14, 9, 12, 5 };
#define NUM_SECTORS (sizeof(SECTORS) / sizeof(*SECTORS))
@@ -431,34 +448,27 @@ void test_curses_match(int start_points)
void init_colours()
{
- init_pair(1, 82, 0); // 140
- init_pair(2, 154, 0); // 100
- init_pair(3, 226, 0); // 60
- init_pair(4, 214, 0); // 40
- init_pair(5, 202, 0); // 20
- init_pair(6, 196, 0); // 0
- init_pair(7, 235, 0); // darts
- init_pair(8, 244, 0); // visit
+ FOREACH_COLOUR(GEN_COLOUR_INIT_PAIR)
}
int points_colour(int points)
{
if (points >= 180)
- return COLOR_PAIR(1) | A_BOLD;
+ return COLOR_PAIR(C_140) | A_BOLD;
else if (points >= 140)
- return COLOR_PAIR(1);
+ return COLOR_PAIR(C_140);
else if (points >= 100)
- return COLOR_PAIR(2);
+ return COLOR_PAIR(C_100);
else if (points >= 60)
- return COLOR_PAIR(3);
+ return COLOR_PAIR(C_60);
else if (points >= 40)
- return COLOR_PAIR(4);
+ return COLOR_PAIR(C_40);
else if (points >= 20)
- return COLOR_PAIR(5);
+ return COLOR_PAIR(C_20);
else if (points > 0)
- return COLOR_PAIR(6);
+ return COLOR_PAIR(C_0);
else
- return COLOR_PAIR(6) | A_BOLD;
+ return COLOR_PAIR(C_0) | A_BOLD;
}
void flushbuf(WINDOW *w, char *buf, int *buflen, int col)
@@ -489,7 +499,7 @@ void draw2(WINDOW *w, struct leg *l1, struct leg *l2)
if (start_visit == 0 && LINES - 3 > n_visits) {
wmove(w, (offset++)-start_visit, 2);
buflen = sprintf(buf, "(%2d)", 0);
- flushbuf(w, buf, &buflen, COLOR_PAIR(8));
+ flushbuf(w, buf, &buflen, COLOR_PAIR(C_VISIT));
buflen = sprintf(buf, " %3d %3d", l1->start, l2->start);
flushbuf(w, buf, &buflen, 0);
}
@@ -497,7 +507,7 @@ void draw2(WINDOW *w, struct leg *l1, struct leg *l2)
for (int i = start_visit; i < n_visits; ++i) {
wmove(w, offset+i-start_visit, 2);
buflen += sprintf(buf + buflen, "(%2d)", i+1);
- flushbuf(w, buf, &buflen, COLOR_PAIR(8));
+ flushbuf(w, buf, &buflen, COLOR_PAIR(C_VISIT));
buflen += sprintf(buf + buflen, " ");
flushbuf(w, buf, &buflen, 0);
@@ -523,7 +533,7 @@ void draw2(WINDOW *w, struct leg *l1, struct leg *l2)
buflen += sprintf(buf + buflen, j == 0 ? " %4s" :" %4s", n);
free(n);
}
- flushbuf(w, buf, &buflen, COLOR_PAIR(7));
+ flushbuf(w, buf, &buflen, COLOR_PAIR(C_DARTS));
}
flushbuf(w, buf, &buflen, 0);