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 int terrain_heights
[32][32];
37 static int terrain_genheights
[32][32];
38 static mg_offsets_t terrain_offsets
[72] = {
46 {0,16,0, -16,-64,-16},
50 {0,32,0, -16,-48,-16},
54 {0,48,0, -16,-32,-16},
58 {0,64,0, -16,-16,-16},
70 {0,112,0, -16,32,-16},
74 {0,128,0, -16,48,-16},
78 {0,144,0, -16,64,-16},
82 {0,160,0, -16,80,-16},
86 {0,176,0, -16,96,-16},
88 {0,192,16, -16,112,0},
89 {16,192,0, 0,112,-16},
90 {0,192,0, -16,112,-16},
92 {0,208,16, -16,128,0},
93 {16,208,0, 0,128,-16},
94 {0,208,0, -16,128,-16},
96 {0,224,16, -16,144,0},
97 {16,224,0, 0,144,-16},
98 {0,224,0, -16,144,-16},
100 {0,240,16, -16,160,0},
101 {16,240,0, 0,160,-16},
102 {0,240,0, -16,160,-16},
103 {16,256,16, 0,176,0},
104 {0,256,16, -16,176,0},
105 {16,256,0, 0,176,-16},
106 {0,256,0, -16,176,-16},
107 {16,272,16, 0,192,0},
108 {0,272,16, -16,192,0},
109 {16,272,0, 0,192,-16},
110 {0,272,0, -16,192,-16}
113 /* generate a ground-level region (-80 to 208) */
114 void mapgen_terrain(pos_t
*p
)
128 for (x
=0; x
<32; x
++) {
129 for (z
=0; z
<32; z
++) {
130 h
= noise_height(p
->x
+x
,p
->z
+z
);
131 terrain_heights
[x
][z
] = h
;
132 terrain_genheights
[x
][z
] = h
;
134 for (y
=0; y
<288; y
++) {
135 b
= &terrain_blocks
[x
][y
][z
];
140 b
->content
= CONTENT_AIR
;
141 }else if (y
< (h
-5)) {
142 b
->content
= CONTENT_STONE
;
143 }else if (y
== h
&& y
>79) {
144 b
->content
= CONTENT_GRASS
;
146 b
->content
= CONTENT_MUD
;
152 for (i
=0; i
<72; i
++) {
153 cp
.x
= p
->x
+terrain_offsets
[i
].cx
;
154 cp
.y
= p
->y
+terrain_offsets
[i
].cy
;
155 cp
.z
= p
->z
+terrain_offsets
[i
].cz
;
156 ch
= mapgen_create_chunk(&cp
);
158 for (x
=0; x
<16; x
++) {
159 for (y
=0; y
<16; y
++) {
160 for (z
=0; z
<16; z
++) {
161 b
= &terrain_blocks
[x
+terrain_offsets
[i
].x
][y
+terrain_offsets
[i
].y
][z
+terrain_offsets
[i
].z
];
162 cb
= &ch
->blocks
[x
][y
][z
];
163 cb
->content
= b
->content
;
164 cb
->param1
= b
->param1
;
165 cb
->param2
= b
->param2
;
166 cb
->param3
= b
->param3
;
167 if (cb
->content
!= CONTENT_AIR
)
173 ch
->state
&= ~CHUNK_STATE_UNGENERATED
;
175 ch
->state
|= CHUNK_STATE_EMPTY
;
177 ch
->state
|= CHUNK_STATE_UNDERGROUND
;