3 Copyright (C) 2010-2011 kwolekr, Ryan Kwolek <kwolekr2@cs.scranton.edu>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "map.h" //for ManualMapVoxelManipulator
32 #define BT_EXTREMEHILLS 7
33 #define BT_MOUNTAINS 8
35 #define BT_DESERTHILLS 10
39 #define BT_BTMASK 0x3F
42 #define BTF_FOREST 0x80
44 #define BGFREQ_1 ( 0.40)
45 #define BGFREQ_2 (BGFREQ_1 + 0.05)
46 #define BGFREQ_3 (BGFREQ_2 + 0.08)
47 #define BGFREQ_4 (BGFREQ_3 + 0.35)
48 #define BGFREQ_5 (BGFREQ_4 + 0.18)
49 //BGFREQ_5 is not checked as an upper bound; it ought to sum up to 1.00, but it's okay if it doesn't.
52 /*float bg1_temps[] = {0.0};
53 int bg1_biomes[] = {BT_OCEAN};
55 float bg2_temps[] = {10.0};
56 int bg2_biomes[] = {BT_GBEACH, BT_SBEACH};
58 float bg3_temps[] = {30.0, 40.0};
59 int bg3_biomes[] = {BT_HILLS, BT_EXTREMEHILLS, BT_MOUNTAINS};
61 float bg4_temps[] = {25.0, 30.0, 35.0, 40.0};
62 int bg4_biomes[] = {BT_HILLS, BT_EXTREMEHILLS, BT_MOUNTAINS, BT_DESERT, BT_DESERTHILLS};
64 float bg5_temps[] = {5.0, 40.0};
65 int bg5_biomes[] = {BT_LAKE, BT_PLAINS, BT_DESERT};*/
68 BiomeDefManager::BiomeDefManager(IGameDef *gamedef) {
69 this->m_gamedef = gamedef;
70 this->ndef = gamedef->ndef();
72 //addDefaultBiomes(); //can't do this in the ctor, too early
76 BiomeDefManager::~BiomeDefManager() {
77 for (int i = 0; i != bgroups.size(); i++)
82 void BiomeDefManager::addBiome() {
87 NoiseParams npmtdef = {0.0, 20.0, v3f(250., 250., 250.), 82341, 5, 0.6};
89 void BiomeDefManager::addDefaultBiomes() {
90 std::vector<Biome *> *bgroup;
93 //bgroup = new std::vector<Biome *>;
97 b->n_top = MapNode(ndef->getId("mapgen_stone"));
98 b->n_filler = b->n_top;
100 b->height_min = -MAP_GENERATION_LIMIT;
101 b->height_max = MAP_GENERATION_LIMIT;
102 b->heat_min = FLT_MIN;
103 b->heat_max = FLT_MAX;
104 b->humidity_min = FLT_MIN;
105 b->humidity_max = FLT_MAX;
109 //bgroup->push_back(b);
110 //bgroups.push_back(bgroup);
114 Biome *BiomeDefManager::getBiome(float bgfreq, float heat, float humidity) {
115 std::vector<Biome *> bgroup;
119 int ngroups = bgroup_freqs.size();
121 return biome_default;
122 for (i = 0; (i != ngroups - 1) && (bgfreq > bgroup_freqs[i]); i++);
123 bgroup = *(bgroups[i]);
125 int nbiomes = bgroup.size();
127 return biome_default;
128 for (i = 0; i != nbiomes - 1; i++) {
130 if (heat >= b->heat_min && heat <= b->heat_max &&
131 humidity >= b->humidity_min && humidity <= b->humidity_max)
135 return biome_default;
139 //////////////////////////// [ Generic biome ] ////////////////////////////////
142 int Biome::getSurfaceHeight(float noise_terrain) {
143 return np->offset + np->scale * noise_terrain;
147 void Biome::genColumn(Mapgen *mg, int x, int z, int y1, int y2) {
148 //printf("(%d, %d): %f\n", x, z, mg->map_terrain[z * mg->ystride + x]);
151 int surfaceh = np->offset + np->scale * mg->map_terrain[(z - mg->node_min.Z) * 80 /*THIS IS TEMPORARY mg->ystride*/ + (x - mg->node_min.X)];
152 //printf("gen column %f\n", );
154 int i = mg->vmanip->m_area.index(x, y, z); //z * mg->zstride + x + (y - mg->vmanip->m_area.MinEdge.Y) * mg->ystride;
155 for (; y <= surfaceh - ntopnodes && y <= y2; y++, i += mg->ystride)
156 mg->vmanip->m_data[i] = n_filler;
157 for (; y <= surfaceh && y <= y2; y++, i += mg->ystride)
158 mg->vmanip->m_data[i] = n_top;
159 for (; y <= y2; y++, i += mg->ystride)
160 mg->vmanip->m_data[i] = mg->n_air;
165 ///////////////////////////// [ Ocean biome ] /////////////////////////////////
169 void BiomeOcean::genColumn(Mapgen *mg, int x, int z, int y1, int y2) {
172 int surfaceh = np->offset + np->scale * mg->map_terrain[z * mg->ystride + x];
174 i = z * mg->zstride + x;
175 for (y = y1; y <= surfaceh - ntopnodes && y <= y2; y++, i += mg->ystride)
176 mg->vmanip->m_data[i] = n_filler;
177 for (; y <= surfaceh && y <= y2; y++, i += mg->ystride)
178 mg->vmanip->m_data[i] = n_top;
179 for (; y <= y2; y++, i += mg->ystride)
180 mg->vmanip->m_data[i] = mg->n_air;
184 ///////////////////////////// [ Nether biome ] /////////////////////////////////
187 int BiomeHell::getSurfaceHeight(float noise_terrain) {
188 return np->offset + np->scale * noise_terrain;
192 void BiomeHell::genColumn(Mapgen *mg, int x, int z, int y1, int y2) {
195 int surfaceh = np->offset + np->scale * mg->map_terrain[z * mg->ystride + x];
197 i = z * mg->zstride + x;
198 for (y = y1; y <= surfaceh - ntopnodes && y <= y2; y++, i += mg->ystride)
199 mg->vmanip->m_data[i] = n_filler;
200 for (; y <= surfaceh && y <= y2; y++, i += mg->ystride)
201 mg->vmanip->m_data[i] = n_top;
202 for (; y <= y2; y++, i += mg->ystride)
203 mg->vmanip->m_data[i] = mg->n_air;
207 ///////////////////////////// [ Aether biome ] ////////////////////////////////
209 /////////////////////////// [ Superflat biome ] ///////////////////////////////
212 int BiomeSuperflat::getSurfaceHeight(float noise_terrain) {
217 void BiomeSuperflat::genColumn(Mapgen *mg, int x, int z, int y1, int y2) {
220 int surfaceh = ntopnodes;
222 i = z * mg->zstride + x;
223 for (y = y1; y <= surfaceh - ntopnodes && y <= y2; y++, i += mg->ystride)
224 mg->vmanip->m_data[i] = n_filler;
225 for (; y <= surfaceh && y <= y2; y++, i += mg->ystride)
226 mg->vmanip->m_data[i] = n_top;
227 for (; y <= y2; y++, i += mg->ystride)
228 mg->vmanip->m_data[i] = mg->n_air;