#define COUNT(x) ( (((x) & 0x08) >> 3) + (((x) & 0x04) >> 2) + \
(((x) & 0x02) >> 1) + ((x) & 0x01) )
-#define TILE_SIZE 32
+#define PREFERRED_TILE_SIZE 32
+#define TILE_SIZE (ds->tilesize)
#define TILE_BORDER 1
#define WINDOW_OFFSET 16
if (a->direction > b->direction)
return +1;
return 0;
-};
+}
static int xyd_cmp_nc(void *av, void *bv) { return xyd_cmp(av, bv); }
return ret;
}
+static const struct game_params net_presets[] = {
+ {5, 5, FALSE, TRUE, 0.0},
+ {7, 7, FALSE, TRUE, 0.0},
+ {9, 9, FALSE, TRUE, 0.0},
+ {11, 11, FALSE, TRUE, 0.0},
+ {13, 11, FALSE, TRUE, 0.0},
+ {5, 5, TRUE, TRUE, 0.0},
+ {7, 7, TRUE, TRUE, 0.0},
+ {9, 9, TRUE, TRUE, 0.0},
+ {11, 11, TRUE, TRUE, 0.0},
+ {13, 11, TRUE, TRUE, 0.0},
+};
+
static int game_fetch_preset(int i, char **name, game_params **params)
{
game_params *ret;
char str[80];
- static const struct { int x, y, wrap; } values[] = {
- {5, 5, FALSE},
- {7, 7, FALSE},
- {9, 9, FALSE},
- {11, 11, FALSE},
- {13, 11, FALSE},
- {5, 5, TRUE},
- {7, 7, TRUE},
- {9, 9, TRUE},
- {11, 11, TRUE},
- {13, 11, TRUE},
- };
-
- if (i < 0 || i >= lenof(values))
+
+ if (i < 0 || i >= lenof(net_presets))
return FALSE;
ret = snew(game_params);
- ret->width = values[i].x;
- ret->height = values[i].y;
- ret->wrapping = values[i].wrap;
- ret->unique = TRUE;
- ret->barrier_probability = 0.0;
+ *ret = net_presets[i];
sprintf(str, "%dx%d%s", ret->width, ret->height,
ret->wrapping ? " wrapping" : "");
static char *validate_params(game_params *params)
{
- if (params->width <= 0 && params->height <= 0)
+ if (params->width <= 0 || params->height <= 0)
return "Width and height must both be greater than zero";
- if (params->width <= 0)
- return "Width must be greater than zero";
- if (params->height <= 0)
- return "Height must be greater than zero";
if (params->width <= 1 && params->height <= 1)
return "At least one of width and height must be greater than one";
if (params->barrier_probability < 0)
break;
}
+ sfree(perim2);
if (i == nperim)
return; /* nothing we can do! */
OFFSET(x2, y2, x1, y1, d1, params);
d2 = F(d1);
-#ifdef DEBUG
+#ifdef GENERATION_DIAGNOSTICS
printf("picked (%d,%d,%c) <-> (%d,%d,%c)\n",
x1, y1, "0RU3L567D9abcdef"[d1], x2, y2, "0RU3L567D9abcdef"[d2]);
#endif
xydp = find234(possibilities, &xyd1, NULL);
if (xydp) {
-#ifdef DEBUG
+#ifdef GENERATION_DIAGNOSTICS
printf("T-piece; removing (%d,%d,%c)\n",
xydp->x, xydp->y, "0RU3L567D9abcdef"[xydp->direction]);
#endif
xydp = find234(possibilities, &xyd1, NULL);
if (xydp) {
-#ifdef DEBUG
+#ifdef GENERATION_DIAGNOSTICS
printf("Loop avoidance; removing (%d,%d,%c)\n",
xydp->x, xydp->y, "0RU3L567D9abcdef"[xydp->direction]);
#endif
if (index(params, tiles, x3, y3))
continue; /* this would create a loop */
-#ifdef DEBUG
+#ifdef GENERATION_DIAGNOSTICS
printf("New frontier; adding (%d,%d,%c)\n",
x2, y2, "0RU3L567D9abcdef"[d]);
#endif
sfree(ui);
}
+static void game_changed_state(game_ui *ui, game_state *oldstate,
+ game_state *newstate)
+{
+}
+
+struct game_drawstate {
+ int started;
+ int width, height;
+ int org_x, org_y;
+ int tilesize;
+ unsigned char *visible;
+};
+
/* ----------------------------------------------------------------------
* Process a move.
*/
ret->last_rotate_dir = 0; /* suppress animation */
ret->last_rotate_x = ret->last_rotate_y = 0;
- } else assert(0);
+ } else {
+ ret = NULL; /* placate optimisers which don't understand assert(0) */
+ assert(0);
+ }
/*
* Check whether the game has been completed.
* Routines for drawing the game position on the screen.
*/
-struct game_drawstate {
- int started;
- int width, height;
- int org_x, org_y;
- unsigned char *visible;
-};
-
static game_drawstate *game_new_drawstate(game_state *state)
{
game_drawstate *ds = snew(game_drawstate);
ds->height = state->height;
ds->org_x = ds->org_y = -1;
ds->visible = snewn(state->width * state->height, unsigned char);
+ ds->tilesize = 0; /* undecided yet */
memset(ds->visible, 0xFF, state->width * state->height);
return ds;
sfree(ds);
}
-static void game_size(game_params *params, int *x, int *y)
+static void game_size(game_params *params, game_drawstate *ds, int *x, int *y,
+ int expand)
{
+ int tsx, tsy, ts;
+ /*
+ * Each window dimension equals the tile size times the grid
+ * dimension, plus TILE_BORDER, plus twice WINDOW_OFFSET.
+ */
+ tsx = (*x - 2*WINDOW_OFFSET - TILE_BORDER) / params->width;
+ tsy = (*y - 2*WINDOW_OFFSET - TILE_BORDER) / params->height;
+ ts = min(tsx, tsy);
+
+ if (expand)
+ ds->tilesize = ts;
+ else
+ ds->tilesize = min(ts, PREFERRED_TILE_SIZE);
+
*x = WINDOW_OFFSET * 2 + TILE_SIZE * params->width + TILE_BORDER;
*y = WINDOW_OFFSET * 2 + TILE_SIZE * params->height + TILE_BORDER;
}
/*
* draw_barrier_corner() and draw_barrier() are passed physical coords
*/
-static void draw_barrier_corner(frontend *fe, int x, int y, int dx, int dy,
- int phase)
+static void draw_barrier_corner(frontend *fe, game_drawstate *ds,
+ int x, int y, int dx, int dy, int phase)
{
int bx = WINDOW_OFFSET + TILE_SIZE * x;
int by = WINDOW_OFFSET + TILE_SIZE * y;
}
}
-static void draw_barrier(frontend *fe, int x, int y, int dir, int phase)
+static void draw_barrier(frontend *fe, game_drawstate *ds,
+ int x, int y, int dir, int phase)
{
int bx = WINDOW_OFFSET + TILE_SIZE * x;
int by = WINDOW_OFFSET + TILE_SIZE * y;
* At least one barrier terminates here. Draw a
* corner.
*/
- draw_barrier_corner(fe, x, y,
+ draw_barrier_corner(fe, ds, x, y,
X(dir)+X(A(dir)), Y(dir)+Y(A(dir)),
phase);
}
for (dir = 1; dir < 0x10; dir <<= 1)
if (barrier(state, GX(x), GY(y)) & dir)
- draw_barrier(fe, x, y, dir, phase);
+ draw_barrier(fe, ds, x, y, dir, phase);
}
unclip(fe);
for (x = 0; x < ds->width; x++) {
if (x+1 < ds->width) {
if (barrier(state, GX(x), GY(0)) & R)
- draw_barrier_corner(fe, x, -1, +1, +1, phase);
+ draw_barrier_corner(fe, ds, x, -1, +1, +1, phase);
if (barrier(state, GX(x), GY(ds->height-1)) & R)
- draw_barrier_corner(fe, x, ds->height, +1, -1, phase);
+ draw_barrier_corner(fe, ds, x, ds->height, +1, -1, phase);
}
if (barrier(state, GX(x), GY(0)) & U) {
- draw_barrier_corner(fe, x, -1, -1, +1, phase);
- draw_barrier_corner(fe, x, -1, +1, +1, phase);
- draw_barrier(fe, x, -1, D, phase);
+ draw_barrier_corner(fe, ds, x, -1, -1, +1, phase);
+ draw_barrier_corner(fe, ds, x, -1, +1, +1, phase);
+ draw_barrier(fe, ds, x, -1, D, phase);
}
if (barrier(state, GX(x), GY(ds->height-1)) & D) {
- draw_barrier_corner(fe, x, ds->height, -1, -1, phase);
- draw_barrier_corner(fe, x, ds->height, +1, -1, phase);
- draw_barrier(fe, x, ds->height, U, phase);
+ draw_barrier_corner(fe, ds, x, ds->height, -1, -1, phase);
+ draw_barrier_corner(fe, ds, x, ds->height, +1, -1, phase);
+ draw_barrier(fe, ds, x, ds->height, U, phase);
}
}
for (y = 0; y < ds->height; y++) {
if (y+1 < ds->height) {
if (barrier(state, GX(0), GY(y)) & D)
- draw_barrier_corner(fe, -1, y, +1, +1, phase);
+ draw_barrier_corner(fe, ds, -1, y, +1, +1, phase);
if (barrier(state, GX(ds->width-1), GY(y)) & D)
- draw_barrier_corner(fe, ds->width, y, -1, +1, phase);
+ draw_barrier_corner(fe, ds, ds->width, y, -1, +1, phase);
}
if (barrier(state, GX(0), GY(y)) & L) {
- draw_barrier_corner(fe, -1, y, +1, -1, phase);
- draw_barrier_corner(fe, -1, y, +1, +1, phase);
- draw_barrier(fe, -1, y, R, phase);
+ draw_barrier_corner(fe, ds, -1, y, +1, -1, phase);
+ draw_barrier_corner(fe, ds, -1, y, +1, +1, phase);
+ draw_barrier(fe, ds, -1, y, R, phase);
}
if (barrier(state, GX(ds->width-1), GY(y)) & R) {
- draw_barrier_corner(fe, ds->width, y, -1, -1, phase);
- draw_barrier_corner(fe, ds->width, y, -1, +1, phase);
- draw_barrier(fe, ds->width, y, L, phase);
+ draw_barrier_corner(fe, ds, ds->width, y, -1, -1, phase);
+ draw_barrier_corner(fe, ds, ds->width, y, -1, +1, phase);
+ draw_barrier(fe, ds, ds->width, y, L, phase);
}
}
}
FALSE, game_text_format,
new_ui,
free_ui,
+ game_changed_state,
make_move,
game_size,
game_colours,
game_flash_length,
game_wants_statusbar,
FALSE, game_timing_state,
+ 0, /* mouse_priorities */
};