2 #include "server/biomes.h"
3 #include "server/server_terrain.h"
4 #include "server/trees.h"
5 #include "server/voxelctx.h"
9 static bool oak_condition(TreeArgsCondition *args)
11 return args->biome == BIOME_HILLS;
14 static void oak_tree_leaf(Voxelctx *ctx)
16 if (!voxelctx_is_alive(ctx))
20 voxelctx_cube(ctx, NODE_OAK_LEAVES, true);
24 voxelctx_x(ctx, 0.5f);
25 voxelctx_sx(ctx, 0.9f);
26 voxelctx_sy(ctx, 0.9f);
27 voxelctx_sz(ctx, 0.8f);
28 voxelctx_ry(ctx, 25.0f);
29 voxelctx_x(ctx, 0.4f);
34 static void oak_tree_top(Voxelctx *ctx)
36 if (!voxelctx_is_alive(ctx))
40 for (int i = 0; i < 8; i++) {
41 voxelctx_rz(ctx, 360.0f / 8.0f);
43 voxelctx_life(ctx, 8);
44 voxelctx_sy(ctx, 2.0f);
45 voxelctx_z(ctx, voxelctx_random(ctx, 0.0f, 5.0f));
46 voxelctx_s(ctx, 5.0f);
47 voxelctx_light(ctx, -0.4f);
48 voxelctx_sat(ctx, 0.5f);
49 voxelctx_hue(ctx, voxelctx_random(ctx, 60.0f, 20.0f));
50 voxelctx_ry(ctx, -45.0f);
57 static void oak_tree_part(Voxelctx *ctx, f32 n)
59 if (!voxelctx_is_alive(ctx))
63 for (int i = 1; i <= n; i++) {
64 voxelctx_z(ctx, 1.0f);
65 voxelctx_rz(ctx, voxelctx_random(ctx, 30.0f, 10.0f));
66 voxelctx_rx(ctx, voxelctx_random(ctx, 0.0f, 10.0f));
69 voxelctx_s(ctx, 4.0f);
70 voxelctx_x(ctx, 0.1f);
71 voxelctx_light(ctx, voxelctx_random(ctx, 0.0f, 0.1f));
72 voxelctx_cylinder(ctx, NODE_OAK_WOOD, true);
75 if (i == (int) (n - 2.0f)) {
84 static void oak_tree(v3s32 pos, List *changed_chunks)
86 Voxelctx *ctx = voxelctx_create(changed_chunks, STAGE_TREES, pos);
88 voxelctx_hue(ctx, 40.0f);
89 voxelctx_light(ctx, -0.5f);
90 voxelctx_sat(ctx, 0.5f);
92 f32 n = voxelctx_random(ctx, 40.0f, 10.0f);
95 for (int i = 1; i <= 3; i++) {
96 voxelctx_rz(ctx, voxelctx_random(ctx, 120.0f, 45.0f));
98 voxelctx_y(ctx, 0.5f);
99 voxelctx_light(ctx, voxelctx_random(ctx, -0.3f, 0.05f));
100 oak_tree_part(ctx, n);
105 voxelctx_delete(ctx);
110 static bool pine_condition(TreeArgsCondition *args)
112 return args->biome == BIOME_MOUNTAIN;
115 static void pine_tree(v3s32 pos, List *changed_chunks)
117 s32 tree_top = (noise2d(pos.x, pos.z, 0, seed + SO_PINETREE_HEIGHT) * 0.5 + 0.5) * (35.0 - 20.0) + 20.0 + pos.y;
118 for (v3s32 tree_pos = pos; tree_pos.y < tree_top; tree_pos.y++) {
119 f64 branch_length = noise3d(tree_pos.x, tree_pos.y, tree_pos.z, 0, seed + SO_PINETREE_BRANCH) * 3.0;
128 s32 dir = (noise3d(tree_pos.x, tree_pos.y, tree_pos.z, 0, seed + SO_PINETREE_BRANCH_DIR) * 0.5 + 0.5) * 4.0;
130 for (v3s32 branch_pos = tree_pos; branch_length > 0; branch_length--, branch_pos = v3s32_add(branch_pos, dirs[dir]))
131 server_terrain_gen_node(branch_pos,
132 terrain_node_create(NODE_PINE_WOOD, (Blob) {0, NULL}),
133 STAGE_TREES, changed_chunks);
135 server_terrain_gen_node(tree_pos,
136 terrain_node_create(NODE_PINE_WOOD, (Blob) {0, NULL}),
137 STAGE_TREES, changed_chunks);
143 static bool palm_condition(TreeArgsCondition *args)
145 return args->biome == BIOME_OCEAN
146 && ocean_get_node_at((v3s32) {args->pos.x, args->pos.y - 0, args->pos.z}, 1, args->row_data) == NODE_AIR
147 && ocean_get_node_at((v3s32) {args->pos.x, args->pos.y - 1, args->pos.z}, 0, args->row_data) == NODE_SAND;
150 static void palm_branch(Voxelctx *ctx)
152 if (!voxelctx_is_alive(ctx))
155 voxelctx_cube(ctx, NODE_PALM_LEAVES, true);
157 voxelctx_z(ctx, 0.5f);
158 voxelctx_s(ctx, 0.8f);
159 voxelctx_rx(ctx, voxelctx_random(ctx, 20.0f, 4.0f));
160 voxelctx_z(ctx, 0.5f);
165 static void palm_tree(v3s32 pos, List *changed_chunks)
167 Voxelctx *ctx = voxelctx_create(changed_chunks, STAGE_TREES, (v3s32) {pos.x, pos.y - 1, pos.z});
169 f32 s = voxelctx_random(ctx, 8.0f, 2.0f);
172 for (int i = 1; i <= s; i++) {
173 voxelctx_z(ctx, 1.0f);
175 voxelctx_s(ctx, 1.0f);
176 voxelctx_light(ctx, voxelctx_random(ctx, -0.8f, 0.1f));
177 voxelctx_sat(ctx, 0.5f);
178 voxelctx_cube(ctx, NODE_PALM_WOOD, true);
184 voxelctx_sat(ctx, 1.0f),
185 voxelctx_light(ctx, -0.5f);
186 voxelctx_hue(ctx, voxelctx_random(ctx, 50.0f, 30.0f));
189 for (int i = 0; i < 6; i++) {
190 voxelctx_rz(ctx, 360.0f / 6.0f);
191 voxelctx_rz(ctx, voxelctx_random(ctx, 0.0f, 10.0f));
193 voxelctx_light(ctx, voxelctx_random(ctx, 0.0f, 0.3f));
194 voxelctx_rx(ctx, 90.0f);
195 voxelctx_s(ctx, 2.0f);
201 voxelctx_delete(ctx);
204 TreeDef tree_definitions[NUM_TREES] = {
208 .probability = 0.0005f,
209 .area_probability = 0.3f,
210 .offset = SO_OAKTREE,
211 .area_offset = SO_OAKTREE_AREA,
212 .condition = &oak_condition,
213 .generate = &oak_tree,
218 .probability = 0.01f,
219 .area_probability = 0.1f,
220 .offset = SO_PINETREE,
221 .area_offset = SO_PINETREE_AREA,
222 .condition = &pine_condition,
223 .generate = &pine_tree,
228 .probability = 0.005f,
229 .area_probability = 0.5f,
230 .offset = SO_PALMTREE,
231 .area_offset = SO_PALMTREE_AREA,
232 .condition = &palm_condition,
233 .generate = &palm_tree,