Compare commits

..

5 Commits

Author SHA1 Message Date
chelsea
afbf333622 Add subtle island terrain relief 2026-05-03 11:58:59 -05:00
chelsea
acd5eaa52f Add dry sand patches near beaches 2026-05-03 11:53:07 -05:00
chelsea
84a0435312 Place wall stairs above walkway surface 2026-05-03 11:39:35 -05:00
chelsea
46f1d24e9d Add stair ramps to border wall walks 2026-05-03 11:32:22 -05:00
chelsea
aed76c3b1b Add dead sequoias and align tower walks 2026-05-03 01:22:38 -05:00
2 changed files with 187 additions and 52 deletions

Binary file not shown.

View File

@@ -131,6 +131,7 @@ static inline double smoothstep01(double v) {
}
static int ground_slope(worldgen_ctx *ctx, int x, int z);
static int is_dry_beach_sand_patch(worldgen_ctx *ctx, const column_data *data, int world_x, int world_z);
static uint16_t select_surface_block(worldgen_ctx *ctx, const column_data *data, int world_x, int world_z);
static void generate_chunk_trails(worldgen_ctx *ctx, int chunk_x, int chunk_z, column_data columns[CHUNK_SIZE][CHUNK_SIZE], chunk_data *out);
static void generate_chunk_redwood_floor(worldgen_ctx *ctx, int chunk_x, int chunk_z,
@@ -692,6 +693,19 @@ static int raw_column_height(worldgen_ctx *ctx, int x, int z) {
height = height * (1.0 - plains_blend) + plains_target * plains_blend;
}
double above_water = height - (double)ctx->sea_level;
if (above_water > -1.5 && above_water < 24.0) {
double island_mask = smoothstep01((above_water + 1.5) / 6.0) * (1.0 - smoothstep01((above_water - 12.0) / 12.0));
island_mask *= 1.0 - build_flats * 0.7;
double rolling = simplex_noise2(&ctx->noise, (warp2_x + 76000) * 0.0045, (warp2_z - 76000) * 0.0045) * 3.2;
rolling += simplex_noise2(&ctx->noise, (warp2_x - 83000) * 0.013, (warp2_z + 83000) * 0.013) * 1.4;
double mound = simplex_noise2(&ctx->noise, (warp2_x + 91000) * 0.021, (warp2_z - 91000) * 0.021) * 0.5 + 0.5;
rolling += mound * mound * 2.0;
double coastal_mask = (1.0 - smoothstep01((above_water - 1.0) / 5.0)) * smoothstep01((above_water + 1.0) / 3.0);
double dune = fabs(simplex_noise2(&ctx->noise, (warp2_x - 47000) * 0.028, (warp2_z + 47000) * 0.028)) * 2.2;
height += (rolling * island_mask) + (dune * coastal_mask * (1.0 - build_flats * 0.85));
}
return (int)height;
}
@@ -937,6 +951,36 @@ static int generate_coal(worldgen_ctx *ctx, int x, int y, int z, int column_heig
// ---------------------------------------------------------------------------
// Terrain block generation
// ---------------------------------------------------------------------------
static int is_dry_beach_sand_patch(worldgen_ctx *ctx, const column_data *data, int world_x, int world_z) {
if (data->has_water && data->water_surface >= data->height) return 0;
if (ground_slope(ctx, world_x, world_z) > 2) return 0;
int nearest_water_dist2 = 9999;
int shore_level = ctx->sea_level;
for (int dx = -7; dx <= 7; ++dx) {
for (int dz = -7; dz <= 7; ++dz) {
int dist2 = dx * dx + dz * dz;
if (dist2 == 0 || dist2 > 49) continue;
column_data neighbor = get_column_data(ctx, world_x + dx, world_z + dz);
if (!neighbor.has_water || neighbor.water_surface < neighbor.height) continue;
if (data->height < neighbor.water_surface - 1 || data->height > neighbor.water_surface + 4) continue;
if (dist2 < nearest_water_dist2) {
nearest_water_dist2 = dist2;
shore_level = neighbor.water_surface;
}
}
}
if (nearest_water_dist2 == 9999) return 0;
if (data->height > shore_level + 4) return 0;
double broad = simplex_noise2(&ctx->noise, (world_x + 72000) * 0.045, (world_z - 72000) * 0.045) * 0.5 + 0.5;
double ragged = simplex_noise2(&ctx->noise, (world_x - 81000) * 0.16, (world_z + 81000) * 0.16) * 0.5 + 0.5;
double patch = broad * 0.7 + ragged * 0.3;
double near_bonus = clamp01((18.0 - (double)nearest_water_dist2) / 18.0) * 0.18;
double height_penalty = clamp01((double)(data->height - shore_level) / 4.0) * 0.16;
return patch + near_bonus - height_penalty > 0.56;
}
static uint16_t select_surface_block(worldgen_ctx *ctx, const column_data *data, int world_x, int world_z) {
if (data->has_water && data->water_surface >= data->height) {
int slope = ground_slope(ctx, world_x, world_z);
@@ -964,6 +1008,9 @@ static uint16_t select_surface_block(worldgen_ctx *ctx, const column_data *data,
double noise = simplex_noise2(&ctx->noise, world_x * 0.02, world_z * 0.02) * 0.5 + 0.5;
if (noise < t) return BLOCK_SNOW;
}
if (is_dry_beach_sand_patch(ctx, data, world_x, world_z)) {
return BLOCK_SAND;
}
if (data->biome == BIOME_REDWOOD_FOREST) {
int slope = ground_slope(ctx, world_x, world_z);
if (slope >= 5) return BLOCK_STONE;
@@ -1598,6 +1645,33 @@ static void build_redwood_titan(worldgen_ctx *ctx, int x, int y, int z, int heig
{1, 0}, {-1, 0}, {0, 1}, {0, -1},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}
};
if (rng_next_f64(rng) < 0.10) {
int snag_height = core_height - rng_range_inclusive(rng, 4, 10);
if (snag_height < 22) snag_height = 22;
int taper_start = snag_height - 5;
for (int dy = 0; dy < snag_height; ++dy) {
int radius = (dy >= taper_start) ? 0 : 1;
for (int dx = -radius; dx <= radius; ++dx) {
for (int dz = -radius; dz <= radius; ++dz) {
if (radius == 1 && abs(dx) == 1 && abs(dz) == 1 && dy > 10 && (dy % 3) == 0) continue;
block_list_push(out, x + dx, y + dy, z + dz, (uint16_t)arch->log_block);
}
}
if (dy > 8 && dy < snag_height - 4 && (dy % 7) == 0) {
int dir = (dy / 7 + rng_range_inclusive(rng, 0, 3)) & 7;
int branch_log = redwood_axis_log(arch->log_block, dirs8[dir][0], dirs8[dir][1]);
int len = 2 + rng_range_inclusive(rng, 0, 2);
for (int step = 2; step <= len + 1; ++step) {
block_list_push(out, x + dirs8[dir][0] * step, y + dy, z + dirs8[dir][1] * step, (uint16_t)branch_log);
}
}
}
for (int i = 0; i < 6; ++i) {
int root_len = 3 + rng_range_inclusive(rng, 0, 2);
place_redwood_root(ctx, x, y, z, dirs8[i][0], dirs8[i][1], root_len, arch->log_block, rng, out);
}
return;
}
int spire = 3 + rng_range_inclusive(rng, 0, 2);
int crown_start = y + core_height / 2 + rng_range_inclusive(rng, 0, 2);
@@ -3616,6 +3690,99 @@ static void generate_chunk_trails(worldgen_ctx *ctx, int chunk_x, int chunk_z, c
}
}
static int border_wall_anchor_base(worldgen_ctx *ctx, int side, int anchor_along, int wall_center) {
int center_x = anchor_along;
int center_z = anchor_along;
switch (side) {
case 0:
center_x = ctx->wall_min_x + wall_center;
break;
case 1:
center_x = ctx->wall_max_x - wall_center;
break;
case 2:
center_z = ctx->wall_min_z + wall_center;
break;
case 3:
center_z = ctx->wall_max_z - wall_center;
break;
}
int smoothed_base = 0;
int weight_sum = 0;
int highest_sample_base = 0;
const int sample_offsets[5] = {-32, -16, 0, 16, 32};
const int sample_weights[5] = {1, 2, 4, 2, 1};
for (int i = 0; i < 5; ++i) {
int sx = center_x;
int sz = center_z;
if (side < 2) {
sz += sample_offsets[i];
} else {
sx += sample_offsets[i];
}
if (sx < ctx->wall_min_x) sx = ctx->wall_min_x;
if (sx > ctx->wall_max_x) sx = ctx->wall_max_x;
if (sz < ctx->wall_min_z) sz = ctx->wall_min_z;
if (sz > ctx->wall_max_z) sz = ctx->wall_max_z;
column_data sample = get_column_data(ctx, sx, sz);
int sample_base = sample.height;
if (sample.has_water && sample.water_surface > sample_base) sample_base = sample.water_surface;
if (i == 0 || sample_base > highest_sample_base) highest_sample_base = sample_base;
smoothed_base += sample_base * sample_weights[i];
weight_sum += sample_weights[i];
}
smoothed_base /= weight_sum;
if (highest_sample_base > smoothed_base + 8) {
smoothed_base += (highest_sample_base - smoothed_base - 8 + 1) / 2;
}
if (smoothed_base < 1) smoothed_base = 1;
if (smoothed_base > CHUNK_HEIGHT - 2) smoothed_base = CHUNK_HEIGHT - 2;
return smoothed_base;
}
static int border_wall_ramp_base(worldgen_ctx *ctx, int side, int along, int wall_center, int tower_spacing) {
int anchor = floor_div_int(along + tower_spacing / 2, tower_spacing) * tower_spacing;
int current_base = border_wall_anchor_base(ctx, side, anchor, wall_center);
int next_anchor = anchor + tower_spacing;
int next_boundary = anchor + tower_spacing / 2;
int next_base = border_wall_anchor_base(ctx, side, next_anchor, wall_center);
int next_delta = next_base - current_base;
if (next_delta != 0) {
int next_span = clamp_int(abs(next_delta), 6, tower_spacing - 8);
int next_start = next_boundary - next_span / 2;
int next_end = next_start + next_span;
if (along >= next_start && along <= next_end) {
int progress = along - next_start;
return current_base + (next_delta * progress + (next_delta > 0 ? next_span / 2 : -next_span / 2)) / next_span;
}
}
int prev_anchor = anchor - tower_spacing;
int prev_boundary = anchor - tower_spacing / 2;
int prev_base = border_wall_anchor_base(ctx, side, prev_anchor, wall_center);
int prev_delta = current_base - prev_base;
if (prev_delta != 0) {
int prev_span = clamp_int(abs(prev_delta), 6, tower_spacing - 8);
int prev_start = prev_boundary - prev_span / 2;
int prev_end = prev_start + prev_span;
if (along >= prev_start && along <= prev_end) {
int progress = along - prev_start;
return prev_base + (prev_delta * progress + (prev_delta > 0 ? prev_span / 2 : -prev_span / 2)) / prev_span;
}
}
return current_base;
}
static uint16_t border_wall_ramp_stair_block(int side, int slope) {
if (side < 2) {
return (slope > 0) ? BLOCK_STONE_BRICK_STAIRS_S : BLOCK_STONE_BRICK_STAIRS_N;
}
return (slope > 0) ? BLOCK_STONE_BRICK_STAIRS_E : BLOCK_STONE_BRICK_STAIRS_W;
}
static void generate_chunk_border_wall(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_data *out) {
if (!ctx->enable_wall) return;
if (ctx->wall_min_x > ctx->wall_max_x || ctx->wall_min_z > ctx->wall_max_z) return;
@@ -3707,57 +3874,15 @@ static void generate_chunk_border_wall(worldgen_ctx *ctx, int chunk_x, int chunk
continue;
}
int center_x = world_x;
int center_z = world_z;
int base_along = (floor_div_int(along, tower_spacing) * tower_spacing) + tower_spacing / 2;
switch (side) {
case 0:
center_x = ctx->wall_min_x + wall_center;
center_z = base_along;
break;
case 1:
center_x = ctx->wall_max_x - wall_center;
center_z = base_along;
break;
case 2:
center_x = base_along;
center_z = ctx->wall_min_z + wall_center;
break;
case 3:
center_x = base_along;
center_z = ctx->wall_max_z - wall_center;
break;
int smoothed_base = border_wall_ramp_base(ctx, side, along, wall_center, tower_spacing);
int prev_base = border_wall_ramp_base(ctx, side, along - 1, wall_center, tower_spacing);
int next_base = border_wall_ramp_base(ctx, side, along + 1, wall_center, tower_spacing);
int stair_slope = 0;
if (next_base > smoothed_base) {
stair_slope = 1;
} else if (prev_base > smoothed_base) {
stair_slope = -1;
}
int smoothed_base = 0;
int weight_sum = 0;
int highest_sample_base = 0;
const int sample_offsets[5] = {-32, -16, 0, 16, 32};
const int sample_weights[5] = {1, 2, 4, 2, 1};
for (int i = 0; i < 5; ++i) {
int sx = center_x;
int sz = center_z;
if (side < 2) {
sz += sample_offsets[i];
} else {
sx += sample_offsets[i];
}
if (sx < ctx->wall_min_x) sx = ctx->wall_min_x;
if (sx > ctx->wall_max_x) sx = ctx->wall_max_x;
if (sz < ctx->wall_min_z) sz = ctx->wall_min_z;
if (sz > ctx->wall_max_z) sz = ctx->wall_max_z;
column_data sample = get_column_data(ctx, sx, sz);
int sample_base = sample.height;
if (sample.has_water && sample.water_surface > sample_base) sample_base = sample.water_surface;
if (i == 0 || sample_base > highest_sample_base) highest_sample_base = sample_base;
smoothed_base += sample_base * sample_weights[i];
weight_sum += sample_weights[i];
}
smoothed_base /= weight_sum;
if (highest_sample_base > smoothed_base + 8) {
smoothed_base += (highest_sample_base - smoothed_base - 8 + 1) / 2;
}
if (smoothed_base < 1) smoothed_base = 1;
if (smoothed_base > CHUNK_HEIGHT - 2) smoothed_base = CHUNK_HEIGHT - 2;
int height = in_tower ? tower_height : wall_height;
int top = smoothed_base + height;
@@ -3815,7 +3940,9 @@ static void generate_chunk_border_wall(worldgen_ctx *ctx, int chunk_x, int chunk
}
if (top + 1 < CHUNK_HEIGHT) {
int rail_opening = ladder_module && side_dist == wall_end && ladder_offset <= 1;
if (!in_tower && !rail_opening && (side_dist == wall_start || side_dist == wall_end)) {
if (side_dist >= wall_center - 1 && side_dist <= wall_center + 1 && stair_slope != 0) {
set_block_with_height(out, dx, dz, top + 1, border_wall_ramp_stair_block(side, stair_slope));
} else if (!in_tower && !rail_opening && (side_dist == wall_start || side_dist == wall_end)) {
uint16_t rail_block = (side < 2) ? BLOCK_IRON_BARS_NS : BLOCK_IRON_BARS_EW;
set_block_with_height(out, dx, dz, top + 1, rail_block);
} else if (in_tower && phase % 4 < 2) {
@@ -3893,7 +4020,15 @@ void worldgen_generate_chunk(worldgen_ctx *ctx, int chunk_x, int chunk_z, chunk_
out->blocks[y][dx][dz] = BLOCK_DIRT;
}
if (cd.height >= 0 && cd.height < CHUNK_HEIGHT) {
out->blocks[cd.height][dx][dz] = select_surface_block(ctx, &cd, world_x, world_z);
uint16_t surface = select_surface_block(ctx, &cd, world_x, world_z);
if (surface == BLOCK_SAND) {
int sand_bottom = cd.height - 2;
if (sand_bottom < dirt_start) sand_bottom = dirt_start;
for (int y = sand_bottom; y < cd.height; ++y) {
if (y > 0 && y < CHUNK_HEIGHT) out->blocks[y][dx][dz] = BLOCK_SAND;
}
}
out->blocks[cd.height][dx][dz] = surface;
}
if (cd.has_water) {
int water_top = cd.water_surface;