ref: eedea4132043cc4c788ee89f1ccb0783893125c5
parent: 0bcb32c9132020ffe2985b542951b05c6ab58b2a
author: Simon Tatham <anakin@pobox.com>
date: Mon Mar 13 15:58:22 EDT 2017
Net: rework status line to cope with empty squares. Another oddity involving an empty square is that if it coincides with the source square for highlights (either by original design of the game id, or because the player Ctrl-moves the source square into an empty grid cell during play), then everything stops being lit up as active. That's fine - you can still play the game using other indications of error, such as the loop detection highlight - but it looks silly for the status line to say 'Active: 1/lots'. So in that situation I suppress the 'active' counter completely; it comes back when you move the source square to somewhere it's _possible_ to highlight more than one square. While I'm at it, I've also removed the active counter in the case where the game is completely solved, because in that situation it's more or less unnecessary anyway, and that way the normal course of play on the default small grid size doesn't overflow the available status line space.
--- a/net.c
+++ b/net.c
@@ -2971,20 +2971,43 @@
* Update the status bar.
*/
{
- char statusbuf[256];
+ char statusbuf[256], *p;
int i, n, n2, a;
+ int complete = FALSE;
- n = state->width * state->height;
- for (i = a = n2 = 0; i < n; i++) {
- if (active[i])
- a++;
- if (state->tiles[i] & 0xF)
- n2++;
+ p = statusbuf;
+ *p = '\0'; /* ensure even an empty status string is terminated */
+
+ if (state->used_solve) {
+ p += sprintf(p, "Auto-solved. ");
+ complete = TRUE;
+ } else if (state->completed) {
+ p += sprintf(p, "COMPLETED! ");
+ complete = TRUE;
}
- sprintf(statusbuf, "%sActive: %d/%d",
- (state->used_solve ? "Auto-solved. " :
- state->completed ? "COMPLETED! " : ""), a, n2);
+ /*
+ * Omit the 'Active: n/N' counter completely if the source
+ * tile is a completely empty one, because then the active
+ * count can't help but read '1'.
+ */
+ if (tile(state, ui->cx, ui->cy) & 0xF) {
+ n = state->width * state->height;
+ for (i = a = n2 = 0; i < n; i++) {
+ if (active[i])
+ a++;
+ if (state->tiles[i] & 0xF)
+ n2++;
+ }
+
+ /*
+ * Also, if we're displaying a completion indicator and
+ * the game is still in its completed state (i.e. every
+ * tile is active), we might as well omit this too.
+ */
+ if (!complete || a < n2)
+ p += sprintf(p, "Active: %d/%d", a, n2);
+ }
status_bar(dr, statusbuf);
}