#include "worldgen.h" #include #include #include #include static int is_cabin_block(uint16_t block) { return block == BLOCK_SPRUCE_PLANKS || block == BLOCK_OAK_PLANKS || block == BLOCK_OAK_LOG_X || block == BLOCK_OAK_LOG_Z || block == BLOCK_SPRUCE_LOG_X || block == BLOCK_SPRUCE_LOG_Z || block == BLOCK_GLASS_PANE || block == BLOCK_GLASS || block == BLOCK_SPRUCE_STAIRS_E || block == BLOCK_SPRUCE_STAIRS_W || block == BLOCK_LADDER_N || block == BLOCK_LADDER_S || block == BLOCK_LADDER_E || block == BLOCK_LADDER_W || block == BLOCK_SPRUCE_DOOR_N_LOWER || block == BLOCK_SPRUCE_DOOR_N_UPPER || block == BLOCK_SPRUCE_DOOR_S_LOWER || block == BLOCK_SPRUCE_DOOR_S_UPPER || block == BLOCK_SPRUCE_DOOR_E_LOWER || block == BLOCK_SPRUCE_DOOR_E_UPPER || block == BLOCK_SPRUCE_DOOR_W_LOWER || block == BLOCK_SPRUCE_DOOR_W_UPPER; } static long parse_long(const char *s) { char *end = NULL; long v = strtol(s, &end, 10); if (!end || *end != '\0') { fprintf(stderr, "Invalid number: %s\n", s); exit(1); } return v; } static void usage(const char *prog) { fprintf(stderr, "Usage: %s [--radius N] [--center-x X] [--center-z Z] [--seed S] [--sea-level L] [--snow-line H] [--trails]\n", prog); } int main(int argc, char **argv) { int radius = 16; int center_x = 0; int center_z = 0; int seed = 123456; int sea_level = 70; int snow_line = INT_MIN; int trails = 0; for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--radius") == 0 && i + 1 < argc) { radius = (int)parse_long(argv[++i]); } else if (strcmp(argv[i], "--center-x") == 0 && i + 1 < argc) { center_x = (int)parse_long(argv[++i]); } else if (strcmp(argv[i], "--center-z") == 0 && i + 1 < argc) { center_z = (int)parse_long(argv[++i]); } else if (strcmp(argv[i], "--seed") == 0 && i + 1 < argc) { seed = (int)parse_long(argv[++i]); } else if (strcmp(argv[i], "--sea-level") == 0 && i + 1 < argc) { sea_level = (int)parse_long(argv[++i]); } else if (strcmp(argv[i], "--snow-line") == 0 && i + 1 < argc) { snow_line = (int)parse_long(argv[++i]); } else if (strcmp(argv[i], "--trails") == 0) { trails = 1; } else if (strcmp(argv[i], "--help") == 0) { usage(argv[0]); return 0; } else { usage(argv[0]); return 1; } } if (snow_line == INT_MIN) snow_line = sea_level + 38; worldgen_ctx ctx; worldgen_init(&ctx, seed, sea_level, snow_line); ctx.enable_trails = trails; if (trails) { worldgen_prepass(&ctx, (center_x - radius) * CHUNK_SIZE, (center_x + radius) * CHUNK_SIZE + CHUNK_SIZE - 1, (center_z - radius) * CHUNK_SIZE, (center_z + radius) * CHUNK_SIZE + CHUNK_SIZE - 1); } long chunks = 0; long cabin_blocks = 0; long cabin_columns = 0; long gravel_columns = 0; long cabin_gravel_columns = 0; long tall_log_columns = 0; long max_oak_log_run = 0; long biome_columns[4] = {0, 0, 0, 0}; double max_redwood_mask = 0.0; for (int cx = center_x - radius; cx <= center_x + radius; ++cx) { for (int cz = center_z - radius; cz <= center_z + radius; ++cz) { chunk_data chunk; worldgen_generate_chunk(&ctx, cx, cz, &chunk); ++chunks; for (int lx = 0; lx < CHUNK_SIZE; ++lx) { for (int lz = 0; lz < CHUNK_SIZE; ++lz) { int wx = cx * CHUNK_SIZE + lx; int wz = cz * CHUNK_SIZE + lz; int biome = worldgen_debug_biome(&ctx, wx, wz); if (biome >= 0 && biome < 4) ++biome_columns[biome]; double redwood_mask = worldgen_debug_redwood_mask(&ctx, wx, wz); if (redwood_mask > max_redwood_mask) max_redwood_mask = redwood_mask; int has_cabin = 0; int has_gravel = 0; int current_run = 0; int best_run = 0; for (int y = 1; y < CHUNK_HEIGHT; ++y) { uint16_t block = chunk.blocks[y][lx][lz]; if (is_cabin_block(block)) { has_cabin = 1; ++cabin_blocks; } if (block == BLOCK_GRAVEL) { has_gravel = 1; } if (block == BLOCK_OAK_LOG) { ++current_run; if (current_run > best_run) best_run = current_run; } else { current_run = 0; } } if (best_run > max_oak_log_run) max_oak_log_run = best_run; if (best_run >= 40) ++tall_log_columns; if (has_cabin) ++cabin_columns; if (has_gravel) ++gravel_columns; if (has_cabin && has_gravel) { ++cabin_gravel_columns; } } } } } printf("chunks=%ld\n", chunks); printf("cabin_blocks=%ld\n", cabin_blocks); printf("cabin_columns=%ld\n", cabin_columns); printf("gravel_columns=%ld\n", gravel_columns); printf("cabin_gravel_columns=%ld\n", cabin_gravel_columns); printf("tall_oak_log_columns=%ld\n", tall_log_columns); printf("max_oak_log_run=%ld\n", max_oak_log_run); printf("biome_west_ky=%ld\n", biome_columns[0]); printf("biome_east_ky=%ld\n", biome_columns[1]); printf("biome_old_growth=%ld\n", biome_columns[2]); printf("biome_redwood=%ld\n", biome_columns[3]); printf("max_redwood_mask=%.6f\n", max_redwood_mask); worldgen_free_trails(&ctx); return 0; }