return TRUE;
}
-void gd_replay_rewind(GdReplay *replay)
-{
- replay->current_playing_pos = 0;
-}
-
-#define REPLAY_BDCFF_UP "u"
-#define REPLAY_BDCFF_UP_RIGHT "ur"
-#define REPLAY_BDCFF_RIGHT "r"
-#define REPLAY_BDCFF_DOWN_RIGHT "dr"
-#define REPLAY_BDCFF_DOWN "d"
-#define REPLAY_BDCFF_DOWN_LEFT "dl"
-#define REPLAY_BDCFF_LEFT "l"
-#define REPLAY_BDCFF_UP_LEFT "ul"
-/* when not moving */
-#define REPLAY_BDCFF_STILL "."
-/* when the fire is pressed */
-#define REPLAY_BDCFF_FIRE "F"
-#define REPLAY_BDCFF_SUICIDE "k"
-
-static char *direction_to_bdcff(GdDirection mov)
-{
- switch (mov)
- {
- /* not moving */
- case GD_MV_STILL: return REPLAY_BDCFF_STILL;
-
- /* directions */
- case GD_MV_UP: return REPLAY_BDCFF_UP;
- case GD_MV_UP_RIGHT: return REPLAY_BDCFF_UP_RIGHT;
- case GD_MV_RIGHT: return REPLAY_BDCFF_RIGHT;
- case GD_MV_DOWN_RIGHT: return REPLAY_BDCFF_DOWN_RIGHT;
- case GD_MV_DOWN: return REPLAY_BDCFF_DOWN;
- case GD_MV_DOWN_LEFT: return REPLAY_BDCFF_DOWN_LEFT;
- case GD_MV_LEFT: return REPLAY_BDCFF_LEFT;
- case GD_MV_UP_LEFT: return REPLAY_BDCFF_UP_LEFT;
-
- default:
- return REPLAY_BDCFF_STILL;
- }
-}
-
-/* same as above; pressing fire will be a capital letter. */
-static char *direction_fire_to_bdcff(GdDirection dir, boolean fire)
-{
- static char mov[10];
-
- strcpy(mov, direction_to_bdcff(dir));
-
- if (fire)
- {
- int i;
-
- for (i = 0; mov[i] != 0; i++)
- mov[i] = g_ascii_toupper(mov[i]);
- }
-
- return mov;
-}
-
-char *gd_replay_movements_to_bdcff(GdReplay *replay)
-{
- int pos;
- GString *str;
-
- str = g_string_new(NULL);
-
- for (pos = 0; pos < replay->movements->len; pos++)
- {
- int num = 1;
- guint8 data;
-
- /* if this is not the first movement, append a space. */
- if (str->len != 0)
- g_string_append_c(str, ' ');
-
- /* if same byte appears, count number of occurrences - something like an rle compression. */
- /* be sure not to cross the array boundaries */
- while (pos < replay->movements->len - 1 &&
- replay->movements->data[pos] == replay->movements->data[pos + 1])
- {
- pos++;
- num++;
- }
-
- data = replay->movements->data[pos];
-
- if (data & GD_REPLAY_SUICIDE_MASK)
- g_string_append(str, REPLAY_BDCFF_SUICIDE);
-
- g_string_append(str, direction_fire_to_bdcff(data & GD_REPLAY_MOVE_MASK,
- data & GD_REPLAY_FIRE_MASK));
-
- if (num != 1)
- g_string_append_printf(str, "%d", num);
- }
-
- return g_string_free(str, FALSE);
-}
-
/* calculate adler checksum for a rendered cave; this can be used for more caves. */
void gd_cave_adler_checksum_more(GdCave *cave, guint32 *a, guint32 *b)
{
GD_OBJECT_LEVEL5
};
-/* bdcff text description of object. caller should free string. */
-char *gd_object_get_bdcff(const GdObject *object)
-{
- GString *str;
- int j;
- const char *type;
-
- switch (object->type)
- {
- case GD_POINT:
- return g_strdup_printf("Point=%d %d %s",
- object->x1, object->y1,
- gd_elements[object->element].filename);
-
- case GD_LINE:
- return g_strdup_printf("Line=%d %d %d %d %s",
- object->x1, object->y1, object->x2, object->y2,
- gd_elements[object->element].filename);
-
- case GD_RECTANGLE:
- return g_strdup_printf("Rectangle=%d %d %d %d %s",
- object->x1, object->y1, object->x2, object->y2,
- gd_elements[object->element].filename);
-
- case GD_FILLED_RECTANGLE:
- /* if elements are not the same */
- if (object->fill_element != object->element)
- return g_strdup_printf("FillRect=%d %d %d %d %s %s",
- object->x1, object->y1, object->x2, object->y2,
- gd_elements[object->element].filename,
- gd_elements[object->fill_element].filename);
-
- /* they are the same */
- return g_strdup_printf("FillRect=%d %d %d %d %s",
- object->x1, object->y1, object->x2, object->y2,
- gd_elements[object->element].filename);
-
- case GD_RASTER:
- return g_strdup_printf("Raster=%d %d %d %d %d %d %s",
- object->x1, object->y1,
- (object->x2 - object->x1) / object->dx + 1,
- (object->y2 - object->y1) / object->dy + 1,
- object->dx, object->dy,
- gd_elements[object->element].filename);
-
- case GD_JOIN:
- return g_strdup_printf("Add=%d %d %s %s",
- object->dx, object->dy,
- gd_elements[object->element].filename,
- gd_elements[object->fill_element].filename);
-
- case GD_FLOODFILL_BORDER:
- return g_strdup_printf("BoundaryFill=%d %d %s %s",
- object->x1, object->y1,
- gd_elements[object->fill_element].filename,
- gd_elements[object->element].filename);
-
- case GD_FLOODFILL_REPLACE:
- return g_strdup_printf("FloodFill=%d %d %s %s",
- object->x1, object->y1,
- gd_elements[object->fill_element].filename,
- gd_elements[object->element].filename);
-
- case GD_MAZE:
- case GD_MAZE_UNICURSAL:
- case GD_MAZE_BRAID:
- switch (object->type)
- {
- case GD_MAZE: type = "perfect"; break;
- case GD_MAZE_UNICURSAL: type = "unicursal"; break;
- case GD_MAZE_BRAID: type = "braid"; break;
- default: break;
- }
-
- return g_strdup_printf("Maze=%d %d %d %d %d %d %d %d %d %d %d %d %s %s %s",
- object->x1, object->y1, object->x2, object->y2,
- object->dx, object->dy,
- object->horiz,
- object->seed[0],
- object->seed[1],
- object->seed[2],
- object->seed[3],
- object->seed[4],
- gd_elements[object->element].filename,
- gd_elements[object->fill_element].filename, type);
-
- case GD_RANDOM_FILL:
- str = g_string_new(NULL);
- /* seed and initial fill */
- g_string_append_printf(str, "%s=%d %d %d %d %d %d %d %d %d %s",
- object->c64_random ? "RandomFillC64" : "RandomFill",
- object->x1, object->y1, object->x2, object->y2,
- object->seed[0],
- object->seed[1],
- object->seed[2],
- object->seed[3],
- object->seed[4],
- gd_elements[object->fill_element].filename);
-
- for (j = 0; j < 4; j++)
- {
- if (object->random_fill_probability[j] != 0)
- g_string_append_printf(str, " %s %d",
- gd_elements[object->random_fill[j]].filename,
- object->random_fill_probability[j]);
- }
-
- if (object->element!=O_NONE)
- g_string_append_printf(str, " %s",
- gd_elements[object->element].filename);
-
- /* free string but do not free char *; return char *. */
- return g_string_free(str, FALSE);
-
- case GD_COPY_PASTE:
- return g_strdup_printf("CopyPaste=%d %d %d %d %d %d %s %s",
- object->x1, object->y1, object->x2, object->y2,
- object->dx, object->dy,
- object->mirror ? "mirror" : "nomirror",
- object->flip?"flip":"noflip");
-
- case NONE:
- break;
- }
-
- return NULL;
-}
-
/* create an INDIVIDUAL POINT CAVE OBJECT */
GdObject *gd_object_new_point(GdObjectLevels levels, int x, int y, GdElement elem)
{