diff --git a/Makefile b/Makefile index 3b547e0..4ca407b 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ test0: bin/back bin/back templates.txt 47 1 test1: bin/back - bin/back templates_lv1.txt 14 1 + bin/back templates_lv1.txt 18 1 test2: bin/back bin/back templates_lv2.txt 52 1 diff --git a/README.md b/README.md index ed9b317..bb79cbf 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,19 @@ > zqsd : move > TAB : exit > p : zoom out -> m : zoom in +> m : zoom in + | EXECUTION | -*make test0 : default template pool (small/medium-sized corridorq)* -*make test1 : more hallways but small corridors only* \ No newline at end of file +*make test-1 : extermly unorganized generation* +*make test0 : default template pool (small/medium-sized corridors)* +*make test1 : large rooms with rotating walls* +*make test2 : more hallways but small corridors only* +*make test3 : long, wide hallways* + +| TILE LIST | +> 0 : nothing +> 1 : wall +> 2 : CCW rotation wall +> 3 : CW rotation wall +> 4, 5, 6, 7 : translation wall (resp. +X, -X, +Y and -Y) + \ No newline at end of file diff --git a/bin/back b/bin/back index c552269..ac2639c 100755 Binary files a/bin/back and b/bin/back differ diff --git a/src/base.c b/src/base.c index f71bf5f..4ac6587 100644 --- a/src/base.c +++ b/src/base.c @@ -265,7 +265,6 @@ bool linked_mem(linkedList* lst, int x, int y, char** flag) { if(lst == NULL) { return false; } - //printf("Searching for (%d, %d) [%d] ; have [%d]\n", x, y, x + 16*y, lst->coord); if(lst->coord == x + 16*y) { *flag = lst->flag; return true ; diff --git a/src/generation.c b/src/generation.c index 4330a4b..bfbe332 100644 --- a/src/generation.c +++ b/src/generation.c @@ -114,7 +114,6 @@ void print_template(int config_id) { void rotateLinkedListCounterClockWise(linkedList* lst) { if(lst != NULL) { uint8_t newc = (lst->coord/16) + 16 * (7- (lst->coord%8)); - //printf("(%d, %d) -> (%d, %d)\n", lst->coord%8, lst->coord/16, newc%8, newc/16); lst->coord = newc ; rotateLinkedListCounterClockWise(lst->next); } @@ -145,6 +144,15 @@ void rotateTemplateCounterClockWise(int config_id) { free(new); } +void transateLinkedList(linkedList* lst, int dy, int dx) { + if(lst != NULL) { + lst->coord = ((lst->coord%8) + dx + 8)%8 + 16*(((lst->coord/16) + dy + 8)%8) ; + transateLinkedList(lst->next, dy, dx); + } +} + +// ---------------------------------------------- // + void rotateChunkCounterClockWise(int chx, int chy) { chunk* ch = gridGet(map, chx, chy); if(ch == NULL) { @@ -175,6 +183,94 @@ void rotateChunkCounterClockWise(int chx, int chy) { free(new); } +void translateChunkX(int chx, int chy) { + chunk* ch = gridGet(map, chx, chy); + if(ch == NULL) { + fprintf(stderr, "ERROR : cannot translate non-existing chunk\n"); + exit(1); + } + + ch->chdata.eastsig = 0 ; + ch->chdata.westsig = 0 ; + + for(int i = 7; i >= 0; i--) { + ch->chdata.eastsig *= 2 ; + ch->chdata.eastsig += (int)(unpack_coord(ch->chdata.lines, 6, i)); + + ch->chdata.westsig *= 2 ; + ch->chdata.eastsig += (int)(unpack_coord(ch->chdata.lines, 7, i)); + } + for(int i = 0; i < 8; i++) { + ch->chdata.lines[i] = (2*ch->chdata.lines[i] + ch->chdata.lines[i]/128)%256 ; + } + transateLinkedList(ch->chdata.meta->next, 1, 0); +} + +void translateChunk_X(int chx, int chy) { + chunk* ch = gridGet(map, chx, chy); + if(ch == NULL) { + fprintf(stderr, "ERROR : cannot translate non-existing chunk\n"); + exit(1); + } + + ch->chdata.eastsig = 0 ; + ch->chdata.westsig = 0 ; + + for(int i = 7; i >= 0; i--) { + ch->chdata.eastsig *= 2 ; + ch->chdata.eastsig += (int)(unpack_coord(ch->chdata.lines, 0, i)); + + ch->chdata.westsig *= 2 ; + ch->chdata.eastsig += (int)(unpack_coord(ch->chdata.lines, 1, i)); + } + for(int i = 0; i < 8; i++) { + ch->chdata.lines[i] = ((ch->chdata.lines[i])/2 + 128*(ch->chdata.lines[i]%2))%256 ; + } + transateLinkedList(ch->chdata.meta->next, -1, 0); +} + +void translateChunkY(int chx, int chy) { + chunk* ch = gridGet(map, chx, chy); + if(ch == NULL) { + fprintf(stderr, "ERROR : cannot translate non-existing chunk\n"); + exit(1); + } + + ch->chdata.eastsig = (2*ch->chdata.eastsig + ch->chdata.eastsig/128)%256; + ch->chdata.westsig = (2*ch->chdata.westsig + ch->chdata.westsig/128)%256; + + uint8_t temp = ch->chdata.lines[0] ; + + for(int i = 0; i < 7; i++) { + ch->chdata.lines[i] = ch->chdata.lines[i+1] ; + } + ch->chdata.lines[7] = temp ; + + transateLinkedList(ch->chdata.meta->next, 0, -1); +} + +void translateChunk_Y(int chx, int chy) { + chunk* ch = gridGet(map, chx, chy); + if(ch == NULL) { + fprintf(stderr, "ERROR : cannot translate non-existing chunk\n"); + exit(1); + } + + ch->chdata.eastsig = (2*ch->chdata.eastsig + ch->chdata.eastsig/128)%256; + ch->chdata.westsig = (2*ch->chdata.westsig + ch->chdata.westsig/128)%256; + + uint8_t temp = ch->chdata.lines[7] ; + + for(int i = 6; i >= 0; i--) { + ch->chdata.lines[i+1] = ch->chdata.lines[i] ; + } + ch->chdata.lines[0] = temp ; + + transateLinkedList(ch->chdata.meta->next, 0, 1); +} + +// ---------------------------------------------- // + bool is_compat_sig_north(int cx, int cy, int idx) { chunk* cp = gridGet(map, cx, cy-1); if(cp == NULL || !cp->chdata.checkCompat) { @@ -373,6 +469,18 @@ void parse_one(FILE* ptr, FILE* ptr2, int index) { } else if(xres == 3) { printf("[%d] SP+1 : %d, %d\n", index, i, 7-j); linked_add(configs[index].meta, i, 7-j, "spinCW"); + } else if(xres == 4) { + printf("[%d] SP+1 : %d, %d\n", index, i, 7-j); + linked_add(configs[index].meta, i, 7-j, "beltX"); + } else if(xres == 5) { + printf("[%d] SP+1 : %d, %d\n", index, i, 7-j); + linked_add(configs[index].meta, i, 7-j, "belt-X"); + } else if(xres == 6) { + printf("[%d] SP+1 : %d, %d\n", index, i, 7-j); + linked_add(configs[index].meta, i, 7-j, "beltY"); + } else if(xres == 7) { + printf("[%d] SP+1 : %d, %d\n", index, i, 7-j); + linked_add(configs[index].meta, i, 7-j, "belt-Y"); } if(j == 7) { diff --git a/src/generation.h b/src/generation.h index 3b2a97d..c716b74 100644 --- a/src/generation.h +++ b/src/generation.h @@ -13,6 +13,14 @@ void rotateTemplateCounterClockWise(int config_id); void rotateChunkCounterClockWise(int chx, int chy); +void translateChunkX(int chx, int chy); + +void translateChunk_X(int chx, int chy); + +void translateChunkY(int chx, int chy); + +void translateChunk_Y(int chx, int chy); + void signature(template t); bool is_compat_with_spins(int cx, int cy, int idx); diff --git a/src/hash.h b/src/hash.h index a65f79b..453276b 100644 --- a/src/hash.h +++ b/src/hash.h @@ -4,8 +4,6 @@ #define GRID_H #include -typedef enum special {ROT_CC, ROT_CW} special ; - typedef struct linkedList { uint8_t coord ; // coord%8 = x ; coord/16 = y char* flag ; diff --git a/src/move.c b/src/move.c index bb87546..4c0b6c8 100644 --- a/src/move.c +++ b/src/move.c @@ -60,9 +60,21 @@ bool useSpecialTiles(int chx, int chy, int x, int y) { player_x = (int)npx ; εx = (double)(npx - (int)npx) ; - player_y = (int)npy ; + player_y = (int)npy ; εy = (double)(npy - (int)npy) ; } + } else if(str_equal(flag, "beltX")) { + translateChunkX(chx, chy); + player_x = (player_x+1)%8; + } else if(str_equal(flag, "belt-X")) { + translateChunk_X(chx, chy); + player_x = (player_x+7)%8; + } else if(str_equal(flag, "beltY")) { + translateChunkY(chx, chy); + player_y = (player_y+7)%8; + } else if(str_equal(flag, "belt-Y")) { + translateChunk_Y(chx, chy); + player_y = (player_y+1)%8; } } return true ; diff --git a/templates_lv1.txt b/templates_lv1.txt index 5d3834b..ee11620 100644 --- a/templates_lv1.txt +++ b/templates_lv1.txt @@ -124,4 +124,40 @@ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +1 1 0 0 0 0 1 1 +1 0 0 0 0 0 0 1 +1 0 0 4 0 0 0 1 +1 0 0 4 0 0 0 1 +1 0 0 4 0 0 0 1 +1 0 0 4 0 0 0 1 +1 0 0 0 0 0 0 1 +1 1 0 0 0 0 1 1 + +1 1 0 0 0 0 1 1 +1 0 0 0 0 0 0 1 +1 0 0 5 0 0 0 1 +1 0 0 5 0 0 0 1 +1 0 0 5 0 0 0 1 +1 0 0 5 5 0 0 1 +1 0 0 0 0 0 0 1 +1 1 0 0 0 0 1 1 + +1 1 0 0 0 0 1 1 +1 0 0 0 0 0 0 1 +1 0 0 6 0 0 0 1 +1 0 0 6 0 0 0 1 +1 0 0 6 6 0 0 1 +1 0 0 6 6 0 0 1 +1 0 0 0 0 0 0 1 +1 1 0 0 0 0 1 1 + +1 1 0 0 0 0 1 1 +1 0 0 0 0 0 0 1 +1 0 0 7 0 0 0 1 +1 0 0 7 7 0 0 1 +1 0 0 7 7 0 0 1 +1 0 0 7 7 0 0 1 +1 0 0 0 0 0 0 1 +1 1 0 0 0 0 1 1 + $ \ No newline at end of file