Skip to content

Commit 570c204

Browse files
paramatkwolekr
authored andcommittedDec 29, 2014
Biome API: Add shore top and shore filler nodes, underwater node, water top node. Add water top depth and shore height parameters. Remove water dust node
1 parent 61dfa91 commit 570c204

File tree

5 files changed

+91
-62
lines changed

5 files changed

+91
-62
lines changed
 

‎src/mapgen_v5.cpp

+24-18
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,12 @@ void MapgenV5::generateBiomes() {
417417

418418
for (s16 z = node_min.Z; z <= node_max.Z; z++)
419419
for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
420-
Biome *biome = (Biome *)bmgr->get(biomemap[index]);
421-
s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
422-
s16 y0_top = biome->depth_top;
423-
s16 y0_filler = biome->depth_top + dfiller;
420+
Biome *biome = (Biome *)bmgr->get(biomemap[index]);
421+
s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
422+
s16 y0_top = biome->depth_top;
423+
s16 y0_filler = biome->depth_top + dfiller;
424+
s16 shore_max = water_level + biome->height_shore;
425+
s16 depth_water_top = biome->depth_water_top;
424426

425427
s16 nplaced = 0;
426428
u32 i = vm->m_area.index(x, node_max.Y, z);
@@ -439,15 +441,20 @@ void MapgenV5::generateBiomes() {
439441

440442
if (c_below != CONTENT_AIR) {
441443
if (nplaced < y0_top) {
442-
// A hack to prevent dirt_with_grass from being
443-
// placed below water. TODO: fix later
444-
content_t c_place = ((y < water_level) &&
445-
(biome->c_top == c_dirt_with_grass)) ?
446-
c_dirt : biome->c_top;
447-
vm->m_data[i] = MapNode(c_place);
444+
if(y < water_level)
445+
vm->m_data[i] = MapNode(biome->c_underwater);
446+
else if(y <= shore_max)
447+
vm->m_data[i] = MapNode(biome->c_shore_top);
448+
else
449+
vm->m_data[i] = MapNode(biome->c_top);
448450
nplaced++;
449451
} else if (nplaced < y0_filler && nplaced >= y0_top) {
450-
vm->m_data[i] = MapNode(biome->c_filler);
452+
if(y < water_level)
453+
vm->m_data[i] = MapNode(biome->c_underwater);
454+
else if(y <= shore_max)
455+
vm->m_data[i] = MapNode(biome->c_shore_filler);
456+
else
457+
vm->m_data[i] = MapNode(biome->c_filler);
451458
nplaced++;
452459
} else if (c == c_stone) {
453460
have_air = false;
@@ -469,7 +476,10 @@ void MapgenV5::generateBiomes() {
469476
} else if (c == c_water_source) {
470477
have_air = true;
471478
nplaced = 0;
472-
vm->m_data[i] = MapNode(biome->c_water);
479+
if(y > water_level - depth_water_top)
480+
vm->m_data[i] = MapNode(biome->c_water_top);
481+
else
482+
vm->m_data[i] = MapNode(biome->c_water);
473483
} else if (c == CONTENT_AIR) {
474484
have_air = true;
475485
nplaced = 0;
@@ -480,6 +490,7 @@ void MapgenV5::generateBiomes() {
480490
}
481491
}
482492

493+
483494
void MapgenV5::dustTopNodes() {
484495
v3s16 em = vm->m_area.getExtent();
485496
u32 index = 0;
@@ -504,12 +515,7 @@ void MapgenV5::dustTopNodes() {
504515
}
505516

506517
content_t c = vm->m_data[vi].getContent();
507-
if (c == biome->c_water && biome->c_dust_water != CONTENT_IGNORE) {
508-
if (y < node_min.Y - 1)
509-
continue;
510-
511-
vm->m_data[vi] = MapNode(biome->c_dust_water);
512-
} else if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE
518+
if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE
513519
&& c != biome->c_dust) {
514520
if (y == node_max.Y + 1)
515521
continue;

‎src/mapgen_v7.cpp

+23-18
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,12 @@ void MapgenV7::generateBiomes() {
516516

517517
for (s16 z = node_min.Z; z <= node_max.Z; z++)
518518
for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
519-
Biome *biome = (Biome *)bmgr->get(biomemap[index]);
520-
s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
521-
s16 y0_top = biome->depth_top;
522-
s16 y0_filler = biome->depth_top + dfiller;
519+
Biome *biome = (Biome *)bmgr->get(biomemap[index]);
520+
s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
521+
s16 y0_top = biome->depth_top;
522+
s16 y0_filler = biome->depth_top + dfiller;
523+
s16 shore_max = water_level + biome->height_shore;
524+
s16 depth_water_top = biome->depth_water_top;
523525

524526
s16 nplaced = 0;
525527
u32 i = vm->m_area.index(x, node_max.Y, z);
@@ -545,15 +547,20 @@ void MapgenV7::generateBiomes() {
545547

546548
if (c_below != CONTENT_AIR) {
547549
if (nplaced < y0_top) {
548-
// A hack to prevent dirt_with_grass from being
549-
// placed below water. TODO: fix later
550-
content_t c_place = ((y < water_level) &&
551-
(biome->c_top == c_dirt_with_grass)) ?
552-
c_dirt : biome->c_top;
553-
vm->m_data[i] = MapNode(c_place);
550+
if(y < water_level)
551+
vm->m_data[i] = MapNode(biome->c_underwater);
552+
else if(y <= shore_max)
553+
vm->m_data[i] = MapNode(biome->c_shore_top);
554+
else
555+
vm->m_data[i] = MapNode(biome->c_top);
554556
nplaced++;
555557
} else if (nplaced < y0_filler && nplaced >= y0_top) {
556-
vm->m_data[i] = MapNode(biome->c_filler);
558+
if(y < water_level)
559+
vm->m_data[i] = MapNode(biome->c_underwater);
560+
else if(y <= shore_max)
561+
vm->m_data[i] = MapNode(biome->c_shore_filler);
562+
else
563+
vm->m_data[i] = MapNode(biome->c_filler);
557564
nplaced++;
558565
} else if (c == c_stone) {
559566
have_air = false;
@@ -575,7 +582,10 @@ void MapgenV7::generateBiomes() {
575582
} else if (c == c_water_source) {
576583
have_air = true;
577584
nplaced = 0;
578-
vm->m_data[i] = MapNode(biome->c_water);
585+
if(y > water_level - depth_water_top)
586+
vm->m_data[i] = MapNode(biome->c_water_top);
587+
else
588+
vm->m_data[i] = MapNode(biome->c_water);
579589
} else if (c == CONTENT_AIR) {
580590
have_air = true;
581591
nplaced = 0;
@@ -611,12 +621,7 @@ void MapgenV7::dustTopNodes() {
611621
}
612622

613623
content_t c = vm->m_data[vi].getContent();
614-
if (c == biome->c_water && biome->c_dust_water != CONTENT_IGNORE) {
615-
if (y < node_min.Y)
616-
continue;
617-
618-
vm->m_data[vi] = MapNode(biome->c_dust_water);
619-
} else if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) {
624+
if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) {
620625
if (y == node_max.Y)
621626
continue;
622627

‎src/mg_biome.cpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,28 @@ BiomeManager::BiomeManager(IGameDef *gamedef) :
3838
// Create default biome to be used in case none exist
3939
Biome *b = new Biome;
4040

41-
b->id = 0;
42-
b->name = "Default";
43-
b->flags = 0;
44-
b->depth_top = 0;
45-
b->depth_filler = 0;
46-
b->height_min = -MAP_GENERATION_LIMIT;
47-
b->height_max = MAP_GENERATION_LIMIT;
48-
b->heat_point = 0.0;
49-
b->humidity_point = 0.0;
41+
b->id = 0;
42+
b->name = "Default";
43+
b->flags = 0;
44+
b->depth_top = 0;
45+
b->depth_filler = 0;
46+
b->height_shore = 0;
47+
b->depth_water_top = 0;
48+
b->height_min = -MAP_GENERATION_LIMIT;
49+
b->height_max = MAP_GENERATION_LIMIT;
50+
b->heat_point = 0.0;
51+
b->humidity_point = 0.0;
5052

5153
NodeResolveInfo *nri = new NodeResolveInfo(b);
5254
nri->nodenames.push_back("air");
5355
nri->nodenames.push_back("air");
56+
nri->nodenames.push_back("air");
57+
nri->nodenames.push_back("air");
58+
nri->nodenames.push_back("air");
5459
nri->nodenames.push_back("mapgen_stone");
5560
nri->nodenames.push_back("mapgen_water_source");
56-
nri->nodenames.push_back("air");
5761
nri->nodenames.push_back("mapgen_water_source");
62+
nri->nodenames.push_back("air");
5863
m_ndef->pendNodeResolve(nri);
5964

6065
add(b);
@@ -121,9 +126,12 @@ void Biome::resolveNodeNames(NodeResolveInfo *nri)
121126
{
122127
m_ndef->getIdFromResolveInfo(nri, "mapgen_dirt_with_grass", CONTENT_AIR, c_top);
123128
m_ndef->getIdFromResolveInfo(nri, "mapgen_dirt", CONTENT_AIR, c_filler);
129+
m_ndef->getIdFromResolveInfo(nri, "mapgen_sand", CONTENT_AIR, c_shore_top);
130+
m_ndef->getIdFromResolveInfo(nri, "mapgen_sand", CONTENT_AIR, c_shore_filler);
131+
m_ndef->getIdFromResolveInfo(nri, "mapgen_sand", CONTENT_AIR, c_underwater);
124132
m_ndef->getIdFromResolveInfo(nri, "mapgen_stone", CONTENT_AIR, c_stone);
133+
m_ndef->getIdFromResolveInfo(nri, "mapgen_water_source", CONTENT_AIR, c_water_top);
125134
m_ndef->getIdFromResolveInfo(nri, "mapgen_water_source", CONTENT_AIR, c_water);
126135
m_ndef->getIdFromResolveInfo(nri, "air", CONTENT_IGNORE, c_dust);
127-
m_ndef->getIdFromResolveInfo(nri, "mapgen_water_source", CONTENT_IGNORE, c_dust_water);
128136
}
129137

‎src/mg_biome.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,18 @@ class Biome : public GenElement, public NodeResolver {
3939

4040
content_t c_top;
4141
content_t c_filler;
42+
content_t c_shore_top;
43+
content_t c_shore_filler;
44+
content_t c_underwater;
4245
content_t c_stone;
46+
content_t c_water_top;
4347
content_t c_water;
4448
content_t c_dust;
45-
content_t c_dust_water;
4649

4750
s16 depth_top;
4851
s16 depth_filler;
52+
s16 height_shore;
53+
s16 depth_water_top;
4954

5055
s16 height_min;
5156
s16 height_max;

‎src/script/lua_api/l_mapgen.cpp

+19-14
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,16 @@ int ModApiMapgen::l_register_biome(lua_State *L)
422422
es_BiomeTerrainType, BIOME_TYPE_NORMAL);
423423
Biome *b = bmgr->create(biometype);
424424

425-
b->name = getstringfield_default(L, index, "name", "");
426-
b->depth_top = getintfield_default(L, index, "depth_top", 1);
427-
b->depth_filler = getintfield_default(L, index, "depth_filler", 3);
428-
b->height_min = getintfield_default(L, index, "height_min", 0);
429-
b->height_max = getintfield_default(L, index, "height_max", 0);
430-
b->heat_point = getfloatfield_default(L, index, "heat_point", 0.);
431-
b->humidity_point = getfloatfield_default(L, index, "humidity_point", 0.);
432-
b->flags = 0; //reserved
425+
b->name = getstringfield_default(L, index, "name", "");
426+
b->depth_top = getintfield_default(L, index, "depth_top", 1);
427+
b->depth_filler = getintfield_default(L, index, "depth_filler", 3);
428+
b->height_shore = getintfield_default(L, index, "height_shore", 3);
429+
b->depth_water_top = getintfield_default(L, index, "depth_water_top", 0);
430+
b->height_min = getintfield_default(L, index, "height_min", 0);
431+
b->height_max = getintfield_default(L, index, "height_max", 0);
432+
b->heat_point = getfloatfield_default(L, index, "heat_point", 0.);
433+
b->humidity_point = getfloatfield_default(L, index, "humidity_point", 0.);
434+
b->flags = 0; //reserved
433435

434436
u32 id = bmgr->add(b);
435437
if (id == (u32)-1) {
@@ -439,12 +441,15 @@ int ModApiMapgen::l_register_biome(lua_State *L)
439441

440442
NodeResolveInfo *nri = new NodeResolveInfo(b);
441443
std::list<std::string> &nnames = nri->nodenames;
442-
nnames.push_back(getstringfield_default(L, index, "node_top", ""));
443-
nnames.push_back(getstringfield_default(L, index, "node_filler", ""));
444-
nnames.push_back(getstringfield_default(L, index, "node_stone", ""));
445-
nnames.push_back(getstringfield_default(L, index, "node_water", ""));
446-
nnames.push_back(getstringfield_default(L, index, "node_dust", ""));
447-
nnames.push_back(getstringfield_default(L, index, "node_dust_water", ""));
444+
nnames.push_back(getstringfield_default(L, index, "node_top", ""));
445+
nnames.push_back(getstringfield_default(L, index, "node_filler", ""));
446+
nnames.push_back(getstringfield_default(L, index, "node_shore_top", ""));
447+
nnames.push_back(getstringfield_default(L, index, "node_shore_filler", ""));
448+
nnames.push_back(getstringfield_default(L, index, "node_underwater", ""));
449+
nnames.push_back(getstringfield_default(L, index, "node_stone", ""));
450+
nnames.push_back(getstringfield_default(L, index, "node_water_top", ""));
451+
nnames.push_back(getstringfield_default(L, index, "node_water", ""));
452+
nnames.push_back(getstringfield_default(L, index, "node_dust", ""));
448453
ndef->pendNodeResolve(nri);
449454

450455
verbosestream << "register_biome: " << b->name << std::endl;

0 commit comments

Comments
 (0)
Please sign in to comment.