diff --git a/worldgen-c/bin/worldgen b/worldgen-c/bin/worldgen index f1c51a9..11f274d 100755 Binary files a/worldgen-c/bin/worldgen and b/worldgen-c/bin/worldgen differ diff --git a/worldgen-c/src/worldgen.c b/worldgen-c/src/worldgen.c index 67a3df2..527d9c7 100644 --- a/worldgen-c/src/worldgen.c +++ b/worldgen-c/src/worldgen.c @@ -1549,6 +1549,22 @@ static void build_cabin_roof(const cabin_blueprint *bp, int chunk_x, int chunk_z } } +static void carve_cabin_path(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_data *chunk, column_data columns[CHUNK_SIZE][CHUNK_SIZE], + int start_x, int start_z, int dir_x, int dir_z, int length, int width) { + if (dir_x == 0 && dir_z == 0) return; + int chunk_min_x = chunk_x * CHUNK_SIZE; + int chunk_max_x = chunk_min_x + CHUNK_SIZE - 1; + int chunk_min_z = chunk_z * CHUNK_SIZE; + int chunk_max_z = chunk_min_z + CHUNK_SIZE - 1; + int end_x = start_x + dir_x * length; + int end_z = start_z + dir_z * length; + if (end_x < chunk_min_x + 1) end_x = chunk_min_x + 1; + if (end_x > chunk_max_x - 1) end_x = chunk_max_x - 1; + if (end_z < chunk_min_z + 1) end_z = chunk_min_z + 1; + if (end_z > chunk_max_z - 1) end_z = chunk_max_z - 1; + carve_trail_span(ctx, chunk_x, chunk_z, chunk, columns, start_x, start_z, end_x, end_z, width); +} + static void place_wall_window(chunk_data *chunk, int chunk_origin_x, int chunk_origin_z, int wx, int wz, int window_y, uint16_t window_block, int height) { int lx = wx - chunk_origin_x; @@ -1601,6 +1617,8 @@ static void build_cabin_rect(worldgen_ctx *ctx, const cabin_blueprint *bp, const } } + int ladder_hole_x = INT_MIN; + int ladder_hole_z = INT_MIN; for (int story = 0; story < bp->stories; ++story) { int story_floor = base_floor_y + story * bp->wall_height; if (story_floor >= CHUNK_HEIGHT - 4) break; @@ -1709,14 +1727,16 @@ static void build_cabin_rect(worldgen_ctx *ctx, const cabin_blueprint *bp, const if (bp->has_ladder && story < bp->stories - 1) { int ladder_x = rect_center_x; - int ladder_z = z0 + 1; + int ladder_z = rect_center_z; uint16_t ladder_block = BLOCK_LADDER_S; - switch ((story + door_side) % 4) { - case 0: ladder_x = rect_center_x; ladder_z = z0 + 1; ladder_block = BLOCK_LADDER_S; break; - case 1: ladder_x = rect_center_x; ladder_z = z1 - 1; ladder_block = BLOCK_LADDER_N; break; - case 2: ladder_x = x0 + 1; ladder_z = rect_center_z; ladder_block = BLOCK_LADDER_E; break; - case 3: ladder_x = x1 - 1; ladder_z = rect_center_z; ladder_block = BLOCK_LADDER_W; break; + switch (door_side) { + case 0: ladder_z = z1 - 2; ladder_x = rect_center_x; ladder_block = BLOCK_LADDER_N; break; + case 1: ladder_z = z0 + 2; ladder_x = rect_center_x; ladder_block = BLOCK_LADDER_S; break; + case 2: ladder_x = x1 - 2; ladder_z = rect_center_z; ladder_block = BLOCK_LADDER_E; break; + case 3: ladder_x = x0 + 2; ladder_z = rect_center_z; ladder_block = BLOCK_LADDER_W; break; } + ladder_x = clamp_int(ladder_x, x0 + 1, x1 - 1); + ladder_z = clamp_int(ladder_z, z0 + 1, z1 - 1); int lx = ladder_x - chunk_origin_x; int lz = ladder_z - chunk_origin_z; if (lx >= 0 && lx < CHUNK_SIZE && lz >= 0 && lz < CHUNK_SIZE) { @@ -1727,6 +1747,8 @@ static void build_cabin_rect(worldgen_ctx *ctx, const cabin_blueprint *bp, const if (next_floor < CHUNK_HEIGHT) { set_block_with_height(chunk, lx, lz, next_floor, BLOCK_AIR); } + ladder_hole_x = ladder_x; + ladder_hole_z = ladder_z; } } } @@ -1734,6 +1756,17 @@ static void build_cabin_rect(worldgen_ctx *ctx, const cabin_blueprint *bp, const int roof_base = base_floor_y + bp->wall_height * bp->stories; build_cabin_roof(bp, chunk_x, chunk_z, chunk, rect_center_x, rect_center_z, rect->half_w, rect->half_l, roof_base, rng); + int attic_y = roof_base; + for (int wz = z0 + 1; wz <= z1 - 1; ++wz) { + for (int wx = x0 + 1; wx <= x1 - 1; ++wx) { + if (wx == ladder_hole_x && wz == ladder_hole_z) continue; + int lx = wx - chunk_origin_x; + int lz = wz - chunk_origin_z; + if (lx < 0 || lx >= CHUNK_SIZE || lz < 0 || lz >= CHUNK_SIZE) continue; + set_block_with_height(chunk, lx, lz, attic_y, bp->floor_block); + } + } + if (has_door) { int step_x = (door_side == 2) ? -1 : (door_side == 3) ? 1 : 0; int step_z = (door_side == 0) ? -1 : (door_side == 1) ? 1 : 0; @@ -1919,8 +1952,11 @@ static void connect_cabin_to_trail(worldgen_ctx *ctx, int chunk_x, int chunk_z, int step_z = (door_side == 0) ? -1 : (door_side == 1) ? 1 : 0; int start_x = door_x + step_x; int start_z = door_z + step_z; + int spur_len = 6; + if (path_width < 2) path_width = 2; + carve_cabin_path(ctx, chunk_x, chunk_z, chunk, columns, start_x, start_z, step_x, step_z, spur_len, path_width); int target_x = 0, target_z = 0; - if (!find_nearest_trail_block(columns, chunk, chunk_x, chunk_z, start_x, start_z, 24, &target_x, &target_z)) { + if (!find_nearest_trail_block(columns, chunk, chunk_x, chunk_z, start_x, start_z, 48, &target_x, &target_z)) { return; } carve_trail_span(ctx, chunk_x, chunk_z, chunk, columns, start_x, start_z, target_x, target_z, path_width > 0 ? path_width : 2);