1 /************************************************************************
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
24 #include "content_block.h"
26 typedef struct mg_offsets_s
{
35 static block_t terrain_blocks
[32][288][32];
36 static mg_offsets_t terrain_offsets
[72] = {
44 {0,16,0, -16,-64,-16},
48 {0,32,0, -16,-48,-16},
52 {0,48,0, -16,-32,-16},
56 {0,64,0, -16,-16,-16},
68 {0,112,0, -16,32,-16},
72 {0,128,0, -16,48,-16},
76 {0,144,0, -16,64,-16},
80 {0,160,0, -16,80,-16},
84 {0,176,0, -16,96,-16},
86 {0,192,16, -16,112,0},
87 {16,192,0, 0,112,-16},
88 {0,192,0, -16,112,-16},
90 {0,208,16, -16,128,0},
91 {16,208,0, 0,128,-16},
92 {0,208,0, -16,128,-16},
94 {0,224,16, -16,144,0},
95 {16,224,0, 0,144,-16},
96 {0,224,0, -16,144,-16},
98 {0,240,16, -16,160,0},
99 {16,240,0, 0,160,-16},
100 {0,240,0, -16,160,-16},
101 {16,256,16, 0,176,0},
102 {0,256,16, -16,176,0},
103 {16,256,0, 0,176,-16},
104 {0,256,0, -16,176,-16},
105 {16,272,16, 0,192,0},
106 {0,272,16, -16,192,0},
107 {16,272,0, 0,192,-16},
108 {0,272,0, -16,192,-16}
111 /* generate a ground-level region (-80 to 208) */
112 void mapgen_terrain(pos_t
*p
)
125 for (x
=0; x
<32; x
++) {
126 for (z
=0; z
<32; z
++) {
127 /* TODO: get the real height here */
128 h
= noise_height(p
->x
+x
,p
->z
+z
);
130 for (y
=0; y
<288; y
++) {
131 b
= &terrain_blocks
[x
][y
][z
];
136 b
->content
= CONTENT_AIR
;
137 }else if (y
< (h
-5)) {
138 b
->content
= CONTENT_STONE
;
139 }else if (y
== h
&& y
>79) {
140 b
->content
= CONTENT_GRASS
;
142 b
->content
= CONTENT_MUD
;
148 for (i
=0; i
<72; i
++) {
149 cp
.x
= p
->x
+terrain_offsets
[i
].cx
;
150 cp
.y
= p
->y
+terrain_offsets
[i
].cy
;
151 cp
.z
= p
->z
+terrain_offsets
[i
].cz
;
152 ch
= mapgen_create_chunk(&cp
);
153 for (x
=0; x
<16; x
++) {
154 for (y
=0; y
<16; y
++) {
155 for (z
=0; z
<16; z
++) {
156 b
= &terrain_blocks
[x
+terrain_offsets
[i
].x
][y
+terrain_offsets
[i
].y
][z
+terrain_offsets
[i
].z
];
157 cb
= &ch
->blocks
[x
][y
][z
];
158 cb
->content
= b
->content
;
159 cb
->param1
= b
->param1
;
160 cb
->param2
= b
->param2
;
161 cb
->param3
= b
->param3
;
166 ch
->state
&= ~CHUNK_STATE_UNGENERATED
;