Introduce a new game backend function (there seem to have been a lot
[sgt/puzzles] / netslide.c
index 5e98222..e6751fe 100644 (file)
@@ -13,8 +13,6 @@
 #include "puzzles.h"
 #include "tree234.h"
 
-#define PI 3.141592653589793238462643383279502884197169399
-
 #define MATMUL(xr,yr,m,x,y) do { \
     float rx, ry, xx = (x), yy = (y), *mat = (m); \
     rx = mat[0] * xx + mat[2] * yy; \
@@ -131,7 +129,7 @@ static int xyd_cmp(void *av, void *bv) {
     if (a->direction > b->direction)
        return +1;
     return 0;
-};
+}
 
 static struct xyd *new_xyd(int x, int y, int direction)
 {
@@ -163,34 +161,35 @@ static game_params *default_params(void)
     return ret;
 }
 
+static const struct { int x, y, wrap, bprob; const char* desc; }
+netslide_presets[] = {
+    {3, 3, FALSE, 1.0, " easy"},
+    {3, 3, FALSE, 0.0, " medium"},
+    {3, 3, TRUE,  0.0, " hard"},
+    {4, 4, FALSE, 1.0, " easy"},
+    {4, 4, FALSE, 0.0, " medium"},
+    {4, 4, TRUE,  0.0, " hard"},
+    {5, 5, FALSE, 1.0, " easy"},
+    {5, 5, FALSE, 0.0, " medium"},
+    {5, 5, TRUE,  0.0, " hard"},
+};
+
 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, bprob; const char* desc; } values[] = {
-        {3, 3, FALSE, 1.0, " easy"},
-        {3, 3, FALSE, 0.0, " medium"},
-        {3, 3, TRUE,  0.0, " hard"},
-        {4, 4, FALSE, 1.0, " easy"},
-        {4, 4, FALSE, 0.0, " medium"},
-        {4, 4, TRUE,  0.0, " hard"},
-        {5, 5, FALSE, 1.0, " easy"},
-        {5, 5, FALSE, 0.0, " medium"},
-        {5, 5, TRUE,  0.0, " hard"},
-    };
-
-    if (i < 0 || i >= lenof(values))
+
+    if (i < 0 || i >= lenof(netslide_presets))
         return FALSE;
 
     ret = snew(game_params);
-    ret->width = values[i].x;
-    ret->height = values[i].y;
-    ret->wrapping = values[i].wrap;
-    ret->barrier_probability = values[i].bprob;
+    ret->width = netslide_presets[i].x;
+    ret->height = netslide_presets[i].y;
+    ret->wrapping = netslide_presets[i].wrap;
+    ret->barrier_probability = netslide_presets[i].bprob;
     ret->movetarget = 0;
 
-    sprintf(str, "%dx%d%s", ret->width, ret->height,
-            values[i].desc);
+    sprintf(str, "%dx%d%s", ret->width, ret->height, netslide_presets[i].desc);
 
     *name = dupstr(str);
     *params = ret;
@@ -316,12 +315,8 @@ static game_params *custom_params(config_item *cfg)
 
 static char *validate_params(game_params *params)
 {
-    if (params->width <= 1 && params->height <= 1)
+    if (params->width <= 1 || params->height <= 1)
        return "Width and height must both be greater than one";
-    if (params->width <= 1)
-       return "Width must be greater than one";
-    if (params->height <= 1)
-       return "Height must be greater than one";
     if (params->barrier_probability < 0)
        return "Barrier probability may not be negative";
     if (params->barrier_probability > 1)
@@ -334,7 +329,7 @@ static char *validate_params(game_params *params)
  */
 
 static char *new_game_desc(game_params *params, random_state *rs,
-                          game_aux_info **aux)
+                          game_aux_info **aux, int interactive)
 {
     tree234 *possibilities, *barriertree;
     int w, h, x, y, cx, cy, nbarriers;
@@ -422,7 +417,7 @@ static char *new_game_desc(game_params *params, random_state *rs,
 
        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
@@ -449,7 +444,7 @@ static char *new_game_desc(game_params *params, random_state *rs,
            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
@@ -476,7 +471,7 @@ static char *new_game_desc(game_params *params, random_state *rs,
            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
@@ -511,7 +506,7 @@ static char *new_game_desc(game_params *params, random_state *rs,
            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
@@ -738,7 +733,7 @@ static char *validate_desc(game_params *params, char *desc)
  * Construct an initial game state, given a description and parameters.
  */
 
-static game_state *new_game(game_params *params, char *desc)
+static game_state *new_game(midend_data *me, game_params *params, char *desc)
 {
     game_state *state;
     int w, h, x, y;
@@ -1050,8 +1045,13 @@ static void slide_col(game_state *state, int dir, int col)
     slide_col_int(state->width, state->height, state->tiles, dir, col);
 }
 
+static void game_changed_state(game_ui *ui, game_state *oldstate,
+                               game_state *newstate)
+{
+}
+
 static game_state *make_move(game_state *state, game_ui *ui,
-                            int x, int y, int button)
+                             game_drawstate *ds, int x, int y, int button)
 {
     int cx, cy;
     int n, dx, dy;
@@ -1725,6 +1725,11 @@ static int game_wants_statusbar(void)
     return TRUE;
 }
 
+static int game_timing_state(game_state *state)
+{
+    return FALSE;
+}
+
 #ifdef COMBINED
 #define thegame netslide
 #endif
@@ -1749,6 +1754,7 @@ const struct game thegame = {
     FALSE, game_text_format,
     new_ui,
     free_ui,
+    game_changed_state,
     make_move,
     game_size,
     game_colours,
@@ -1758,4 +1764,6 @@ const struct game thegame = {
     game_anim_length,
     game_flash_length,
     game_wants_statusbar,
+    FALSE, game_timing_state,
+    0,                                /* mouse_priorities */
 };