Added a help file, mostly thanks to Jacob.
[sgt/puzzles] / cube.c
diff --git a/cube.c b/cube.c
index ccc8689..72ac527 100644 (file)
--- a/cube.c
+++ b/cube.c
@@ -6,11 +6,13 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <ctype.h>
 #include <math.h>
 
 #include "puzzles.h"
 
 const char *const game_name = "Cube";
+const char *const game_winhelp_topic = "games.cube";
 const int game_can_configure = TRUE;
 
 #define MAXVERTICES 20
@@ -160,7 +162,7 @@ enum {
 enum { LEFT, RIGHT, UP, DOWN, UP_LEFT, UP_RIGHT, DOWN_LEFT, DOWN_RIGHT };
 
 #define GRID_SCALE 48.0F
-#define ROLLTIME 0.1F
+#define ROLLTIME 0.13F
 
 #define SQ(x) ( (x) * (x) )
 
@@ -276,6 +278,37 @@ game_params *dup_params(game_params *params)
     return ret;
 }
 
+game_params *decode_params(char const *string)
+{
+    game_params *ret = default_params();
+
+    switch (*string) {
+      case 't': ret->solid = TETRAHEDRON; string++; break;
+      case 'c': ret->solid = CUBE;        string++; break;
+      case 'o': ret->solid = OCTAHEDRON;  string++; break;
+      case 'i': ret->solid = ICOSAHEDRON; string++; break;
+      default: break;
+    }
+    ret->d1 = ret->d2 = atoi(string);
+    while (*string && isdigit(*string)) string++;
+    if (*string == 'x') {
+        string++;
+        ret->d2 = atoi(string);
+    }
+
+    return ret;
+}
+
+char *encode_params(game_params *params)
+{
+    char data[256];
+
+    assert(params->solid >= 0 && params->solid < 4);
+    sprintf(data, "%c%dx%d", "tcoi"[params->solid], params->d1, params->d2);
+
+    return dupstr(data);
+}
+
 static void enum_grid_squares(game_params *params,
                               void (*callback)(void *, struct grid_square *),
                               void *ctx)
@@ -653,7 +686,7 @@ char *new_game_seed(game_params *params, random_state *rs)
     /*
      * Choose a non-blue square for the polyhedron.
      */
-    sprintf(p, ":%d", data.gridptrs[0][random_upto(rs, m)]);
+    sprintf(p, ",%d", data.gridptrs[0][random_upto(rs, m)]);
 
     sfree(data.gridptrs[0]);
     sfree(flags);
@@ -824,13 +857,13 @@ char *validate_seed(game_params *params, char *seed)
        /* NB if seed[j]=='\0' that will also be caught here, so we're safe */
     }
 
-    if (seed[i] != ':')
-       return "Expected ':' after hex digits";
+    if (seed[i] != ',')
+       return "Expected ',' after hex digits";
 
     i++;
     do {
        if (seed[i] < '0' || seed[i] > '9')
-           return "Expected decimal integer after ':'";
+           return "Expected decimal integer after ','";
        i++;
     } while (seed[i]);
 
@@ -883,7 +916,7 @@ game_state *new_game(game_params *params, char *seed)
                j = 8;
        }
 
-       if (*p == ':')
+       if (*p == ',')
            p++;
 
        state->current = atoi(p);
@@ -950,7 +983,16 @@ void free_game(game_state *state)
     sfree(state);
 }
 
-game_state *make_move(game_state *from, int x, int y, int button)
+game_ui *new_ui(game_state *state)
+{
+    return NULL;
+}
+
+void free_ui(game_ui *ui)
+{
+}
+
+game_state *make_move(game_state *from, game_ui *ui, int x, int y, int button)
 {
     int direction;
     int pkey[2], skey[2], dkey[2];
@@ -1309,7 +1351,8 @@ void game_free_drawstate(game_drawstate *ds)
 }
 
 void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
-                 game_state *state, float animtime, float flashtime)
+                 game_state *state, game_ui *ui,
+                 float animtime, float flashtime)
 {
     int i, j;
     struct bbox bb = find_bbox(&state->params);