From f452f34a6abf49150ef1a4af0d8f352a1852b3f3 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 17 Aug 2024 19:13:44 +0200 Subject: [PATCH] added support for BDCFF token "AddBackward" --- src/game_bd/bd_caveobject.c | 54 ++++++++++++++++++++++++++++--------- src/game_bd/bd_caveobject.h | 2 ++ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/game_bd/bd_caveobject.c b/src/game_bd/bd_caveobject.c index 337d3642..ebdc1b47 100644 --- a/src/game_bd/bd_caveobject.c +++ b/src/game_bd/bd_caveobject.c @@ -55,7 +55,7 @@ char *gd_object_get_bdcff(const GdObject *object) return getStringPrint("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_element_properties[object->element].filename); case GD_JOIN: - return getStringPrint("Add=%d %d %s %s", object->dx, object->dy, gd_element_properties[object->element].filename, gd_element_properties[object->fill_element].filename); + return getStringPrint("%s=%d %d %s %s", (object->backwards ? "AddBackward" : "Add"), object->dx, object->dy, gd_element_properties[object->element].filename, gd_element_properties[object->fill_element].filename); case GD_FLOODFILL_BORDER: return getStringPrint("BoundaryFill=%d %d %s %s", object->x1, object->y1, gd_element_properties[object->fill_element].filename, gd_element_properties[object->element].filename); @@ -476,7 +476,8 @@ GdObject *gd_object_new_from_string(char *str) // JOIN if (strcasecmp(name, "Join") == 0 || - strcasecmp(name, "Add") == 0) + strcasecmp(name, "Add") == 0 || + strcasecmp(name, "AddBackward") == 0) { if (sscanf(param, "%d %d %s %s", &object.dx, &object.dy, elem0, elem1) == 4) { @@ -484,6 +485,8 @@ GdObject *gd_object_new_from_string(char *str) object.element = gd_get_element_from_string (elem0); object.fill_element = gd_get_element_from_string (elem1); + object.backwards = (strcasecmp(name, "AddBackward") == 0); + return get_memcpy(&object, sizeof (GdObject)); } @@ -883,20 +886,45 @@ static void draw_join(GdCave *cave, const GdObject *object) { int x, y; - for (y = 0; y < cave->h; y++) + if (!object->backwards) { - for (x = 0; x < cave->w; x++) + // from top to bottom + for (y = 0; y < cave->h; y++) + { + for (x = 0; x < cave->w; x++) + { + if (cave->map[y][x] == object->element) + { + int nx = x + object->dx; + int ny = y + object->dy; + // this one implements wraparound for joins. + // it is needed by many caves in profi boulder series + while (nx >= cave->w) + nx -= cave->w, ny++; + + gd_cave_store_rc(cave, nx, ny, object->fill_element, object); + } + } + } + } + else + { + // from bottom to top + for (y = cave->h - 1; y >= 0; y--) { - if (cave->map[y][x] == object->element) + for (x = cave->w - 1; x >= 0; x--) { - int nx = x + object->dx; - int ny = y + object->dy; - // this one implements wraparound for joins. - // it is needed by many caves in profi boulder series - while (nx >= cave->w) - nx -= cave->w, ny++; - - gd_cave_store_rc(cave, nx, ny, object->fill_element, object); + if (cave->map[y][x] == object->element) + { + int nx = x + object->dx; + int ny = y + object->dy; + // this one implements wraparound for joins. + // it is needed by many caves in profi boulder series + while (nx < 0) + nx += cave->w, ny--; + + gd_cave_store_rc(cave, nx, ny, object->fill_element, object); + } } } } diff --git a/src/game_bd/bd_caveobject.h b/src/game_bd/bd_caveobject.h index 13dbcffd..381f690f 100644 --- a/src/game_bd/bd_caveobject.h +++ b/src/game_bd/bd_caveobject.h @@ -65,6 +65,8 @@ typedef struct _gd_object int dx, dy; // distance of elements for raster or join GdElement element, fill_element; // element type + boolean backwards; // if true, search goes from bottom to top + int seed[5]; // for maze and random fill int horiz; // for maze -- 2.34.1