diff --git a/bin/back b/bin/back index 594527e..f27538c 100755 Binary files a/bin/back and b/bin/back differ diff --git a/src/generation.c b/src/generation.c index dd7ba3c..e538418 100644 --- a/src/generation.c +++ b/src/generation.c @@ -20,6 +20,9 @@ Grid map ; +int emptyChance = 75 ; // 1 out of this number for empty chunk override +int sizeIncreaseChance = 15 ; // % for an empty chunk to increase in size + template* configs ; array** matches ; int n_configs = 18; @@ -42,6 +45,7 @@ imgs digits ; imgs letters ; template full ; +template empty ; // yes Valentin I learned to use .h the intended way xD @@ -56,6 +60,7 @@ template copy(template src) { new.id = src.id ; new.eastsig = src.eastsig; new.westsig = src.westsig; + new.checkCompat = src.checkCompat ; new.lines = malloc(sizeof(uint8_t)*8); for(int i = 0; i < 8; i++) { new.lines[i] = src.lines[i]; @@ -77,6 +82,16 @@ void generate_chunk(int x, int y, int config_id) { gridInsert(map, x, y, new); } +void generate_chunk_raw(int x, int y, template tpl) { + chunk* new = malloc(sizeof(chunk)) ; + new->chx = x ; + new->chy = y ; + new->draw_id = draw_par - 2; + new->chdata = copy(tpl); + //printf("%d\n", new->chdata.checkCompat); + gridInsert(map, x, y, new); +} + void print_template(int config_id) { for(int i = 0; i < 8; i++) { uint8_t rem = configs[config_id].lines[i]; @@ -122,7 +137,7 @@ void rotateTemplateClockWise(int config_id) { bool is_compat_sig_north(int cx, int cy, int idx) { chunk* cp = gridGet(map, cx, cy-1); - if(cp == NULL) { + if(cp == NULL || !cp->chdata.checkCompat) { return true; } else { return cp->chdata.lines[7] == configs[idx].lines[0]; @@ -130,7 +145,7 @@ bool is_compat_sig_north(int cx, int cy, int idx) { } bool is_compat_sig_south(int cx, int cy, int idx) { chunk* cp = gridGet(map, cx, cy+1); - if(cp == NULL) { + if(cp == NULL || !cp->chdata.checkCompat) { return true; } else { return cp->chdata.lines[0] == configs[idx].lines[7]; @@ -138,7 +153,7 @@ bool is_compat_sig_south(int cx, int cy, int idx) { } bool is_compat_sig_east(int cx, int cy, int idx) { chunk* cp = gridGet(map, cx+1, cy); - if(cp == NULL) { + if(cp == NULL || !cp->chdata.checkCompat) { return true; } else { return cp->chdata.westsig == configs[idx].eastsig; @@ -146,7 +161,7 @@ bool is_compat_sig_east(int cx, int cy, int idx) { } bool is_compat_sig_west(int cx, int cy, int idx) { chunk* cp = gridGet(map, cx-1, cy); - if(cp == NULL) { + if(cp == NULL || !cp->chdata.checkCompat) { return true; } else { return cp->chdata.eastsig == configs[idx].westsig; @@ -217,7 +232,32 @@ void generate_chunk_all(int cx, int cy) { }; //printf("generating %d at (%d, %d)...\n", idx, cx, cy); //print_template(idx); - generate_chunk(cx, cy, idx); + int R = rand()%emptyChance; + //printf("%d/%d\n", R, emptyChance); + if(R != 0) { + generate_chunk(cx, cy, idx); + } else { + generate_chunk_raw(cx, cy, empty); + if(rand()%100 < sizeIncreaseChance) { + if(!(gridMem(map, cx+1, cy) || gridMem(map, cx+1, cy+1) || gridMem(map, cx, cy+1))) { + generate_chunk_raw(cx+1, cy, empty); + generate_chunk_raw(cx, cy+1, empty); + generate_chunk_raw(cx+1, cy+1, empty); + } else if(!(gridMem(map, cx+1, cy) || gridMem(map, cx+1, cy-1) || gridMem(map, cx, cy-1))) { + generate_chunk_raw(cx+1, cy, empty); + generate_chunk_raw(cx, cy-1, empty); + generate_chunk_raw(cx+1, cy-1, empty); + } else if(!(gridMem(map, cx-1, cy) || gridMem(map, cx-1, cy-1) || gridMem(map, cx, cy-1))) { + generate_chunk_raw(cx-1, cy, empty); + generate_chunk_raw(cx, cy-1, empty); + generate_chunk_raw(cx-1, cy-1, empty); + } else if(!(gridMem(map, cx-1, cy) || gridMem(map, cx-1, cy+1) || gridMem(map, cx, cy+1))) { + generate_chunk_raw(cx-1, cy, empty); + generate_chunk_raw(cx, cy+1, empty); + generate_chunk_raw(cx-1, cy+1, empty); + } + } + } } void initialize(SDL_Renderer* renderer) { @@ -227,11 +267,33 @@ void initialize(SDL_Renderer* renderer) { import_digits(renderer); full.lines = malloc(sizeof(uint8_t)*8); + full.westsig = 255 ; + full.eastsig = 255 ; + + full.checkCompat = false ; + for(int i = 0; i < 8; i++) { full.lines[i] = 255 ; }; full.id = -1 ; + empty.lines = malloc(sizeof(uint8_t)*8); + empty.westsig = 0 ; + empty.eastsig = 0 ; + + empty.checkCompat = false ; + + empty.lines[0] = 0 ; + empty.lines[1] = 0 ; + empty.lines[2] = 0 ; + empty.lines[3] = 24 ; + empty.lines[4] = 24 ; + empty.lines[5] = 0 ; + empty.lines[6] = 0 ; + empty.lines[7] = 0 ; + + empty.id = -1 ; + generate_chunk(0, 0, 2); } @@ -242,6 +304,7 @@ void destroy() { free_digits(letters); free(full.lines); + free(empty.lines); } void parse_one(FILE* ptr, FILE* ptr2, int index) { @@ -283,6 +346,7 @@ void parse_configs(char* filename, int n_conf) { configs[i].id = i; configs[i].eastsig = 0 ; configs[i].westsig = 0 ; + configs[i].checkCompat = true ; configs[i].lines = malloc(sizeof(uint8_t)*8); for(int j = 0; j < 8; j++) { configs[i].lines[j] = 0; diff --git a/src/generation.h b/src/generation.h index 3d52732..4b635b2 100644 --- a/src/generation.h +++ b/src/generation.h @@ -5,6 +5,8 @@ bool unpack_coord(uint8_t* lines, int cx, int cy); void generate_chunk(int x, int y, int config_id); +void generate_chunk_raw(int x, int y, template tpl); + void print_template(int config_id); void rotateTemplateClockWise(int config_id); diff --git a/src/hash.h b/src/hash.h index 3cca3fb..910202d 100644 --- a/src/hash.h +++ b/src/hash.h @@ -8,6 +8,8 @@ typedef struct template { uint8_t id ; uint8_t* lines ; // len = 8 + bool checkCompat ; + uint8_t eastsig ; uint8_t westsig ; } template ; diff --git a/src/structure.h b/src/structure.h index b33afd8..b210eb6 100644 --- a/src/structure.h +++ b/src/structure.h @@ -15,6 +15,9 @@ typedef enum cardinal {NORTH, EAST, SOUTH, WEST} cardinal ; extern Grid map ; +extern int emptyChance ; +extern int sizeIncreaseChance ; + extern int zoom ; extern int render_distance ; @@ -46,5 +49,6 @@ extern imgs digits ; extern imgs letters ; extern template full ; +extern template empty ; #endif \ No newline at end of file