summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/constants.h3
-rw-r--r--src/content_craft.cpp1
-rw-r--r--src/content_mapblock.cpp176
-rw-r--r--src/content_mapnode.cpp118
-rw-r--r--src/content_mapnode.h8
-rw-r--r--src/environment.cpp39
-rw-r--r--src/environment.h1
-rw-r--r--src/game.cpp14
-rw-r--r--src/map.cpp132
-rw-r--r--src/mapgen.cpp10
-rw-r--r--src/mapnode.cpp5
-rw-r--r--src/mapnode.h25
12 files changed, 375 insertions, 157 deletions
diff --git a/src/constants.h b/src/constants.h
index 21ab2a64c..1af5f1f1b 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -30,9 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define DEBUGFILE "debug.txt"
-#define WATER_ALPHA 160
-//#define WATER_ALPHA 190
-
// Define for simulating the quirks of sending through internet.
// Causes the socket class to deliberately drop random packets.
// This disables unit testing of socket and connection.
diff --git a/src/content_craft.cpp b/src/content_craft.cpp
index 481ea1a63..20ab5f069 100644
--- a/src/content_craft.cpp
+++ b/src/content_craft.cpp
@@ -486,6 +486,7 @@ void craft_set_creative_inventory(Player *player)
CONTENT_CHEST,
CONTENT_FURNACE,
CONTENT_SIGN_WALL,
+ CONTENT_LAVASOURCE,
CONTENT_IGNORE
};
diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp
index ed2cd766a..c0845ec57 100644
--- a/src/content_mapblock.cpp
+++ b/src/content_mapblock.cpp
@@ -133,23 +133,12 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
//bool smooth_lighting = g_settings.getBool("smooth_lighting");
bool invisible_stone = g_settings.getBool("invisible_stone");
- float node_water_level = 1.0;
+ float node_liquid_level = 1.0;
if(new_style_water)
- node_water_level = 0.85;
+ node_liquid_level = 0.85;
v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
- // Flowing water material
- video::SMaterial material_water1;
- material_water1.setFlag(video::EMF_LIGHTING, false);
- material_water1.setFlag(video::EMF_BACK_FACE_CULLING, false);
- material_water1.setFlag(video::EMF_BILINEAR_FILTER, false);
- material_water1.setFlag(video::EMF_FOG_ENABLE, true);
- material_water1.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
- AtlasPointer pa_water1 = g_texturesource->getTexture(
- g_texturesource->getTextureId("water.png"));
- material_water1.setTexture(0, pa_water1.atlas);
-
// New-style leaves material
video::SMaterial material_leaves1;
material_leaves1.setFlag(video::EMF_LIGHTING, false);
@@ -337,30 +326,40 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
collector.append(material, vertices, 4, indices, 6);
}
/*
- Add flowing water to mesh
+ Add flowing liquid to mesh
*/
- else if(n.getContent() == CONTENT_WATER)
+ else if(content_features(n).liquid_type == LIQUID_FLOWING)
{
- bool top_is_water = false;
+ assert(content_features(n).special_material);
+ video::SMaterial &liquid_material =
+ *content_features(n).special_material;
+ assert(content_features(n).special_atlas);
+ AtlasPointer &pa_liquid1 =
+ *content_features(n).special_atlas;
+
+ bool top_is_same_liquid = false;
MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
- if(ntop.getContent() == CONTENT_WATER || ntop.getContent() == CONTENT_WATERSOURCE)
- top_is_water = true;
+ content_t c_flowing = content_features(n).liquid_alternative_flowing;
+ content_t c_source = content_features(n).liquid_alternative_source;
+ if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
+ top_is_same_liquid = true;
u8 l = 0;
// Use the light of the node on top if possible
if(content_features(ntop).param_type == CPT_LIGHT)
l = decode_light(ntop.getLightBlend(data->m_daynight_ratio));
- // Otherwise use the light of this node (the water)
+ // Otherwise use the light of this node (the liquid)
else
l = decode_light(n.getLightBlend(data->m_daynight_ratio));
- video::SColor c = MapBlock_LightColor(WATER_ALPHA, l);
+ video::SColor c = MapBlock_LightColor(
+ content_features(n).vertex_alpha, l);
- // Neighbor water levels (key = relative position)
+ // Neighbor liquid levels (key = relative position)
// Includes current node
core::map<v3s16, f32> neighbor_levels;
core::map<v3s16, content_t> neighbor_contents;
core::map<v3s16, u8> neighbor_flags;
- const u8 neighborflag_top_is_water = 0x01;
+ const u8 neighborflag_top_is_same_liquid = 0x01;
v3s16 neighbor_dirs[9] = {
v3s16(0,0,0),
v3s16(0,0,1),
@@ -384,19 +383,20 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
{
content = n2.getContent();
- if(n2.getContent() == CONTENT_WATERSOURCE)
- level = (-0.5+node_water_level) * BS;
- else if(n2.getContent() == CONTENT_WATER)
- level = (-0.5 + ((float)n2.param2 + 0.5) / 8.0
- * node_water_level) * BS;
+ if(n2.getContent() == c_source)
+ level = (-0.5+node_liquid_level) * BS;
+ else if(n2.getContent() == c_flowing)
+ level = (-0.5 + ((float)(n2.param2&LIQUID_LEVEL_MASK)
+ + 0.5) / 8.0 * node_liquid_level) * BS;
// Check node above neighbor.
// NOTE: This doesn't get executed if neighbor
// doesn't exist
p2.Y += 1;
n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
- if(n2.getContent() == CONTENT_WATERSOURCE || n2.getContent() == CONTENT_WATER)
- flags |= neighborflag_top_is_water;
+ if(n2.getContent() == c_source ||
+ n2.getContent() == c_flowing)
+ flags |= neighborflag_top_is_same_liquid;
}
neighbor_levels.insert(neighbor_dirs[i], level);
@@ -404,10 +404,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
neighbor_flags.insert(neighbor_dirs[i], flags);
}
- //float water_level = (-0.5 + ((float)n.param2 + 0.5) / 8.0) * BS;
- //float water_level = neighbor_levels[v3s16(0,0,0)];
-
- // Corner heights (average between four waters)
+ // Corner heights (average between four liquids)
f32 corner_levels[4];
v3s16 halfdirs[4] = {
@@ -421,29 +418,46 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
v3s16 cornerdir = halfdirs[i];
float cornerlevel = 0;
u32 valid_count = 0;
+ u32 air_count = 0;
for(u32 j=0; j<4; j++)
{
v3s16 neighbordir = cornerdir - halfdirs[j];
u8 content = neighbor_contents[neighbordir];
- // Special case for source nodes
- if(content == CONTENT_WATERSOURCE)
+ // If top is liquid, draw starting from top of node
+ if(neighbor_flags[neighbordir] &
+ neighborflag_top_is_same_liquid)
+ {
+ cornerlevel = 0.5*BS;
+ valid_count = 1;
+ break;
+ }
+ // Source is always the same height
+ else if(content == c_source)
{
- cornerlevel = (-0.5+node_water_level)*BS;
+ cornerlevel = (-0.5+node_liquid_level)*BS;
valid_count = 1;
break;
}
- else if(content == CONTENT_WATER)
+ // Flowing liquid has level information
+ else if(content == c_flowing)
{
cornerlevel += neighbor_levels[neighbordir];
valid_count++;
}
else if(content == CONTENT_AIR)
{
+ air_count++;
+ }
+ /*// Air is liquid level 0
+ else if(content == CONTENT_AIR)
+ {
cornerlevel += -0.5*BS;
valid_count++;
- }
+ }*/
}
- if(valid_count > 0)
+ if(air_count >= 2)
+ cornerlevel = -0.5*BS;
+ else if(valid_count > 0)
cornerlevel /= valid_count;
corner_levels[i] = cornerlevel;
}
@@ -469,24 +483,24 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
v3s16 dir = side_dirs[i];
/*
- If our topside is water and neighbor's topside
- is water, don't draw side face
+ If our topside is liquid and neighbor's topside
+ is liquid, don't draw side face
*/
- if(top_is_water &&
- neighbor_flags[dir] & neighborflag_top_is_water)
+ if(top_is_same_liquid &&
+ neighbor_flags[dir] & neighborflag_top_is_same_liquid)
continue;
u8 neighbor_content = neighbor_contents[dir];
- // Don't draw face if neighbor is not air or water
+ // Don't draw face if neighbor is not air or liquid
if(neighbor_content != CONTENT_AIR
- && neighbor_content != CONTENT_WATER)
+ && neighbor_content != c_source)
continue;
- bool neighbor_is_water = (neighbor_content == CONTENT_WATER);
+ bool neighbor_is_liquid = (neighbor_content == c_source);
- // Don't draw any faces if neighbor is water and top is water
- if(neighbor_is_water == true && top_is_water == false)
+ // Don't draw any faces if neighbor is liquid and top is liquid
+ if(neighbor_is_liquid == true && top_is_same_liquid == false)
continue;
video::S3DVertex vertices[4] =
@@ -496,20 +510,20 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
- pa_water1.x0(), pa_water1.y1()),
+ pa_liquid1.x0(), pa_liquid1.y1()),
video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
- pa_water1.x1(), pa_water1.y1()),
+ pa_liquid1.x1(), pa_liquid1.y1()),
video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
- pa_water1.x1(), pa_water1.y0()),
+ pa_liquid1.x1(), pa_liquid1.y0()),
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
- pa_water1.x0(), pa_water1.y0()),
+ pa_liquid1.x0(), pa_liquid1.y0()),
};
/*
- If our topside is water, set upper border of face
+ If our topside is liquid, set upper border of face
at upper border of node
*/
- if(top_is_water)
+ if(top_is_same_liquid)
{
vertices[2].Pos.Y = 0.5*BS;
vertices[3].Pos.Y = 0.5*BS;
@@ -524,16 +538,16 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
}
/*
- If neighbor is water, lower border of face is corner
- water levels
+ If neighbor is liquid, lower border of face is corner
+ liquid levels
*/
- if(neighbor_is_water)
+ if(neighbor_is_liquid)
{
vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
}
/*
- If neighbor is not water, lower border of face is
+ If neighbor is not liquid, lower border of face is
lower border of node
*/
else
@@ -558,14 +572,14 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
u16 indices[] = {0,1,2,2,3,0};
// Add to mesh collector
- collector.append(material_water1, vertices, 4, indices, 6);
+ collector.append(liquid_material, vertices, 4, indices, 6);
}
/*
Generate top side, if appropriate
*/
- if(top_is_water == false)
+ if(top_is_same_liquid == false)
{
video::S3DVertex vertices[4] =
{
@@ -574,13 +588,13 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
- pa_water1.x0(), pa_water1.y1()),
+ pa_liquid1.x0(), pa_liquid1.y1()),
video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
- pa_water1.x1(), pa_water1.y1()),
+ pa_liquid1.x1(), pa_liquid1.y1()),
video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
- pa_water1.x1(), pa_water1.y0()),
+ pa_liquid1.x1(), pa_liquid1.y0()),
video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
- pa_water1.x0(), pa_water1.y0()),
+ pa_liquid1.x0(), pa_liquid1.y0()),
};
// This fixes a strange bug
@@ -588,7 +602,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
for(s32 i=0; i<4; i++)
{
- //vertices[i].Pos.Y += water_level;
+ //vertices[i].Pos.Y += liquid_level;
//vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
s32 j = corner_resolve[i];
vertices[i].Pos.Y += corner_levels[j];
@@ -597,29 +611,33 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
u16 indices[] = {0,1,2,2,3,0};
// Add to mesh collector
- collector.append(material_water1, vertices, 4, indices, 6);
+ collector.append(liquid_material, vertices, 4, indices, 6);
}
}
/*
Add water sources to mesh if using new style
*/
- else if(n.getContent() == CONTENT_WATERSOURCE && new_style_water)
+ else if(content_features(n).liquid_type == LIQUID_SOURCE
+ && new_style_water)
{
- //bool top_is_water = false;
+ assert(content_features(n).special_material);
+ video::SMaterial &liquid_material =
+ *content_features(n).special_material;
+ assert(content_features(n).special_atlas);
+ AtlasPointer &pa_liquid1 =
+ *content_features(n).special_atlas;
+
bool top_is_air = false;
MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
- /*if(n.getContent() == CONTENT_WATER || n.getContent() == CONTENT_WATERSOURCE)
- top_is_water = true;*/
if(n.getContent() == CONTENT_AIR)
top_is_air = true;
- /*if(top_is_water == true)
- continue;*/
if(top_is_air == false)
continue;
u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
- video::SColor c = MapBlock_LightColor(WATER_ALPHA, l);
+ video::SColor c = MapBlock_LightColor(
+ content_features(n).vertex_alpha, l);
video::S3DVertex vertices[4] =
{
@@ -628,24 +646,24 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
- pa_water1.x0(), pa_water1.y1()),
+ pa_liquid1.x0(), pa_liquid1.y1()),
video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
- pa_water1.x1(), pa_water1.y1()),
+ pa_liquid1.x1(), pa_liquid1.y1()),
video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
- pa_water1.x1(), pa_water1.y0()),
+ pa_liquid1.x1(), pa_liquid1.y0()),
video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
- pa_water1.x0(), pa_water1.y0()),
+ pa_liquid1.x0(), pa_liquid1.y0()),
};
for(s32 i=0; i<4; i++)
{
- vertices[i].Pos.Y += (-0.5+node_water_level)*BS;
+ vertices[i].Pos.Y += (-0.5+node_liquid_level)*BS;
vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
}
u16 indices[] = {0,1,2,2,3,0};
// Add to mesh collector
- collector.append(material_water1, vertices, 4, indices, 6);
+ collector.append(liquid_material, vertices, 4, indices, 6);
}
/*
Add leaves if using new style
diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp
index b164033db..f45853c4a 100644
--- a/src/content_mapnode.cpp
+++ b/src/content_mapnode.cpp
@@ -24,6 +24,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode.h"
#include "content_nodemeta.h"
+#define WATER_ALPHA 160
+
+#define WATER_VISC 1
+#define LAVA_VISC 7
+
// TODO: Get rid of these and set up some attributes like toughness,
// fluffyness, and a funciton to calculate time and durability loss
// (and sound? and whatever else) from them
@@ -372,6 +377,22 @@ void content_mapnode_init()
f->liquid_type = LIQUID_FLOWING;
f->liquid_alternative_flowing = CONTENT_WATER;
f->liquid_alternative_source = CONTENT_WATERSOURCE;
+ f->liquid_viscosity = WATER_VISC;
+ f->vertex_alpha = WATER_ALPHA;
+ if(f->special_material == NULL && g_texturesource)
+ {
+ // Flowing water material
+ f->special_material = new video::SMaterial;
+ f->special_material->setFlag(video::EMF_LIGHTING, false);
+ f->special_material->setFlag(video::EMF_BACK_FACE_CULLING, false);
+ f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
+ f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
+ f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
+ AtlasPointer *pa_water1 = new AtlasPointer(g_texturesource->getTexture(
+ g_texturesource->getTextureId("water.png")));
+ f->special_material->setTexture(0, pa_water1->atlas);
+ f->special_atlas = pa_water1;
+ }
i = CONTENT_WATERSOURCE;
f = &content_features(i);
@@ -404,6 +425,103 @@ void content_mapnode_init()
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->liquid_alternative_flowing = CONTENT_WATER;
f->liquid_alternative_source = CONTENT_WATERSOURCE;
+ f->liquid_viscosity = WATER_VISC;
+ f->vertex_alpha = WATER_ALPHA;
+ if(f->special_material == NULL && g_texturesource)
+ {
+ // Flowing water material
+ f->special_material = new video::SMaterial;
+ f->special_material->setFlag(video::EMF_LIGHTING, false);
+ f->special_material->setFlag(video::EMF_BACK_FACE_CULLING, false);
+ f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
+ f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
+ f->special_material->MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
+ AtlasPointer *pa_water1 = new AtlasPointer(g_texturesource->getTexture(
+ g_texturesource->getTextureId("water.png")));
+ f->special_material->setTexture(0, pa_water1->atlas);
+ f->special_atlas = pa_water1;
+ }
+
+ i = CONTENT_LAVA;
+ f = &content_features(i);
+ f->setInventoryTextureCube("lava.png", "lava.png", "lava.png");
+ f->param_type = CPT_LIGHT;
+ f->light_propagates = false;
+ f->light_source = LIGHT_MAX-1;
+ f->solidness = 0; // Drawn separately, makes no faces
+ f->walkable = false;
+ f->pointable = false;
+ f->diggable = false;
+ f->buildable_to = true;
+ f->liquid_type = LIQUID_FLOWING;
+ f->liquid_alternative_flowing = CONTENT_LAVA;
+ f->liquid_alternative_source = CONTENT_LAVASOURCE;
+ f->liquid_viscosity = LAVA_VISC;
+ f->damage_per_second = 4*2;
+ if(f->special_material == NULL && g_texturesource)
+ {
+ // Flowing lava material
+ f->special_material = new video::SMaterial;
+ f->special_material->setFlag(video::EMF_LIGHTING, false);
+ f->special_material->setFlag(video::EMF_BACK_FACE_CULLING, false);
+ f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
+ f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
+ f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ AtlasPointer *pa_lava1 = new AtlasPointer(
+ g_texturesource->getTexture(
+ g_texturesource->getTextureId("lava.png")));
+ f->special_material->setTexture(0, pa_lava1->atlas);
+ f->special_atlas = pa_lava1;
+ }
+
+ i = CONTENT_LAVASOURCE;
+ f = &content_features(i);
+ f->setInventoryTextureCube("lava.png", "lava.png", "lava.png");
+ if(new_style_water)
+ {
+ f->solidness = 0; // drawn separately, makes no faces
+ }
+ else // old style
+ {
+ f->solidness = 2;
+
+ TileSpec t;
+ if(g_texturesource)
+ t.texture = g_texturesource->getTexture("lava.png");
+
+ //t.alpha = 255;
+ //t.material_type = MATERIAL_ALPHA_VERTEX;
+ //t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
+ f->setAllTiles(t);
+ }
+ f->param_type = CPT_LIGHT;
+ f->light_propagates = false;
+ f->light_source = LIGHT_MAX-1;
+ f->walkable = false;
+ f->pointable = false;
+ f->diggable = false;
+ f->buildable_to = true;
+ f->liquid_type = LIQUID_SOURCE;
+ f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
+ f->liquid_alternative_flowing = CONTENT_LAVA;
+ f->liquid_alternative_source = CONTENT_LAVASOURCE;
+ f->liquid_viscosity = LAVA_VISC;
+ f->damage_per_second = 4*2;
+ if(f->special_material == NULL && g_texturesource)
+ {
+ // Flowing lava material
+ f->special_material = new video::SMaterial;
+ f->special_material->setFlag(video::EMF_LIGHTING, false);
+ f->special_material->setFlag(video::EMF_BACK_FACE_CULLING, false);
+ f->special_material->setFlag(video::EMF_BILINEAR_FILTER, false);
+ f->special_material->setFlag(video::EMF_FOG_ENABLE, true);
+ f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ AtlasPointer *pa_lava1 = new AtlasPointer(
+ g_texturesource->getTexture(
+ g_texturesource->getTextureId("lava.png")));
+ f->special_material->setTexture(0, pa_lava1->atlas);
+ f->special_atlas = pa_lava1;
+ }
i = CONTENT_TORCH;
f = &content_features(i);
diff --git a/src/content_mapnode.h b/src/content_mapnode.h
index 9643db746..1f6292ba4 100644
--- a/src/content_mapnode.h
+++ b/src/content_mapnode.h
@@ -37,16 +37,24 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version);
// 0x000...0x07f (0...127): param2 is fully usable
// 126 and 127 are reserved.
// Use these sparingly, only when the extra space in param2 might be needed.
+// Add a space when there is unused space between numbers.
#define CONTENT_STONE 0
+
#define CONTENT_WATER 2
#define CONTENT_TORCH 3
+
#define CONTENT_WATERSOURCE 9
+
#define CONTENT_SIGN_WALL 14
#define CONTENT_CHEST 15
#define CONTENT_FURNACE 16
+
#define CONTENT_FENCE 21
+
#define CONTENT_RAIL 30
#define CONTENT_LADDER 31
+#define CONTENT_LAVA 32
+#define CONTENT_LAVASOURCE 33
// 0x800...0xfff (2048...4095): higher 4 bytes of param2 are not usable
#define CONTENT_GRASS 0x800 //1
diff --git a/src/environment.cpp b/src/environment.cpp
index 2349852f2..d6ff4d826 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -1633,6 +1633,38 @@ void ClientEnvironment::step(float dtime)
}
/*
+ A quick draft of lava damage
+ */
+ if(m_lava_hurt_interval.step(dtime, 1.0))
+ {
+ v3f pf = lplayer->getPosition();
+
+ // Feet, middle and head
+ v3s16 p1 = floatToInt(pf + v3f(0, BS*0.1, 0), BS);
+ MapNode n1 = m_map->getNodeNoEx(p1);
+ v3s16 p2 = floatToInt(pf + v3f(0, BS*0.8, 0), BS);
+ MapNode n2 = m_map->getNodeNoEx(p2);
+ v3s16 p3 = floatToInt(pf + v3f(0, BS*1.6, 0), BS);
+ MapNode n3 = m_map->getNodeNoEx(p2);
+
+ u32 damage_per_second = 0;
+ damage_per_second = MYMAX(damage_per_second,
+ content_features(n1).damage_per_second);
+ damage_per_second = MYMAX(damage_per_second,
+ content_features(n2).damage_per_second);
+ damage_per_second = MYMAX(damage_per_second,
+ content_features(n3).damage_per_second);
+
+ if(damage_per_second != 0)
+ {
+ ClientEnvEvent event;
+ event.type = CEE_PLAYER_DAMAGE;
+ event.player_damage.amount = damage_per_second;
+ m_client_event_queue.push_back(event);
+ }
+ }
+
+ /*
Stuff that can be done in an arbitarily large dtime
*/
for(core::list<Player*>::Iterator i = m_players.begin();
@@ -1917,6 +1949,13 @@ void ClientEnvironment::drawPostFx(video::IVideoDriver* driver, v3f camera_pos)
core::rect<s32> rect(0,0, ss.X, ss.Y);
driver->draw2DRectangle(video::SColor(64, 100, 100, 200), rect);
}
+ else if(content_features(n).solidness == 2 &&
+ g_settings.getBool("free_move") == false)
+ {
+ v2u32 ss = driver->getScreenSize();
+ core::rect<s32> rect(0,0, ss.X, ss.Y);
+ driver->draw2DRectangle(video::SColor(255, 0, 0, 0), rect);
+ }
}
#endif // #ifndef SERVER
diff --git a/src/environment.h b/src/environment.h
index b6767858a..d9248d2ad 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -416,6 +416,7 @@ private:
core::map<u16, ClientActiveObject*> m_active_objects;
Queue<ClientEnvEvent> m_client_event_queue;
IntervalLimiter m_active_object_light_update_interval;
+ IntervalLimiter m_lava_hurt_interval;
};
#endif
diff --git a/src/game.cpp b/src/game.cpp
index ab3852137..7bf1c6f5c 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -2313,6 +2313,13 @@ void the_game(
guienv->drawAll();
/*
+ Environment post fx
+ */
+ {
+ client.getEnv()->drawPostFx(driver, camera_position);
+ }
+
+ /*
Draw hotbar
*/
{
@@ -2335,13 +2342,6 @@ void the_game(
}
/*
- Environment post fx
- */
- {
- client.getEnv()->drawPostFx(driver, camera_position);
- }
-
- /*
End scene
*/
{
diff --git a/src/map.cpp b/src/map.cpp
index dc4459263..3c10e27ee 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -1562,15 +1562,26 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
/*if(initial_size != 0)
dstream<<"transformLiquids(): initial_size="<<initial_size<<std::endl;*/
+ // list of nodes that due to viscosity have not reached their max level height
+ UniqueQueue<v3s16> must_reflow;
+
+ // List of MapBlocks that will require a lighting update (due to lava)
+ core::map<v3s16, MapBlock*> lighting_modified_blocks;
+
while(m_transforming_liquid.size() != 0)
{
+ // This should be done here so that it is done when continue is used
+ if(loopcount >= initial_size * 3)
+ break;
+ loopcount++;
+
/*
Get a queued transforming liquid node
*/
v3s16 p0 = m_transforming_liquid.pop_front();
MapNode n0 = getNodeNoEx(p0);
-
+
/*
Collect information about current node
*/
@@ -1579,7 +1590,7 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
LiquidType liquid_type = content_features(n0.getContent()).liquid_type;
switch (liquid_type) {
case LIQUID_SOURCE:
- liquid_level = 8;
+ liquid_level = LIQUID_LEVEL_SOURCE;
liquid_kind = content_features(n0.getContent()).liquid_alternative_flowing;
break;
case LIQUID_FLOWING:
@@ -1594,18 +1605,11 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
liquid_kind = CONTENT_AIR;
break;
}
-
+
/*
Collect information about the environment
*/
- v3s16 dirs[6] = {
- v3s16( 0, 1, 0), // top
- v3s16( 0,-1, 0), // bottom
- v3s16( 1, 0, 0), // right
- v3s16(-1, 0, 0), // left
- v3s16( 0, 0, 1), // back
- v3s16( 0, 0,-1), // front
- };
+ const v3s16 *dirs = g_6dirs;
NodeNeighbor sources[6]; // surrounding sources
int num_sources = 0;
NodeNeighbor flows[6]; // surrounding flowing liquid nodes
@@ -1618,10 +1622,10 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
for (u16 i = 0; i < 6; i++) {
NeighborType nt = NEIGHBOR_SAME_LEVEL;
switch (i) {
- case 0:
+ case 1:
nt = NEIGHBOR_UPPER;
break;
- case 1:
+ case 4:
nt = NEIGHBOR_LOWER;
break;
}
@@ -1631,9 +1635,15 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
case LIQUID_NONE:
if (nb.n.getContent() == CONTENT_AIR) {
airs[num_airs++] = nb;
+ // if the current node is a water source the neighbor
+ // should be enqueded for transformation regardless of whether the
+ // current node changes or not.
+ if (nb.t != NEIGHBOR_UPPER && liquid_type != LIQUID_NONE)
+ m_transforming_liquid.push_back(npos);
// if the current node happens to be a flowing node, it will start to flow down here.
- if (nb.t == NEIGHBOR_LOWER)
+ if (nb.t == NEIGHBOR_LOWER) {
flowing_down = true;
+ }
} else {
neutrals[num_neutrals++] = nb;
}
@@ -1662,12 +1672,13 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
break;
}
}
-
+
/*
decide on the type (and possibly level) of the current node
*/
content_t new_node_content;
s8 new_node_level = -1;
+ s8 max_node_level = -1;
if (num_sources >= 2 || liquid_type == LIQUID_SOURCE) {
// liquid_kind will be set to either the flowing alternative of the node (if it's a liquid)
// or the flowing alternative of the first of the surrounding sources (if it's air), so
@@ -1676,49 +1687,53 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
} else if (num_sources == 1 && sources[0].t != NEIGHBOR_LOWER) {
// liquid_kind is set properly, see above
new_node_content = liquid_kind;
- new_node_level = 7;
+ max_node_level = new_node_level = LIQUID_LEVEL_MAX;
} else {
// no surrounding sources, so get the maximum level that can flow into this node
for (u16 i = 0; i < num_flows; i++) {
u8 nb_liquid_level = (flows[i].n.param2 & LIQUID_LEVEL_MASK);
switch (flows[i].t) {
case NEIGHBOR_UPPER:
- if (nb_liquid_level + WATER_DROP_BOOST > new_node_level) {
- new_node_level = 7;
- if (nb_liquid_level + WATER_DROP_BOOST < 7)
- new_node_level = nb_liquid_level + WATER_DROP_BOOST;
+ if (nb_liquid_level + WATER_DROP_BOOST > max_node_level) {
+ max_node_level = LIQUID_LEVEL_MAX;
+ if (nb_liquid_level + WATER_DROP_BOOST < LIQUID_LEVEL_MAX)
+ max_node_level = nb_liquid_level + WATER_DROP_BOOST;
}
break;
case NEIGHBOR_LOWER:
break;
case NEIGHBOR_SAME_LEVEL:
if ((flows[i].n.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK &&
- nb_liquid_level > 0 && nb_liquid_level - 1 > new_node_level) {
- new_node_level = nb_liquid_level - 1;
+ nb_liquid_level > 0 && nb_liquid_level - 1 > max_node_level) {
+ max_node_level = nb_liquid_level - 1;
}
break;
}
}
- // don't flow as far in open terrain - if there isn't at least one adjacent solid block,
- // substract another unit from the resulting water level.
- if (!flowing_down && new_node_level >= 1) {
- bool at_wall = false;
- for (u16 i = 0; i < num_neutrals; i++) {
- if (neutrals[i].t == NEIGHBOR_SAME_LEVEL) {
- at_wall = true;
- break;
- }
- }
- if (!at_wall)
- new_node_level -= 1;
- }
-
+
+ u8 viscosity = content_features(liquid_kind).liquid_viscosity;
+ if (viscosity > 1 && max_node_level != liquid_level) {
+ // amount to gain, limited by viscosity
+ // must be at least 1 in absolute value
+ s8 level_inc = max_node_level - liquid_level;
+ if (level_inc < -viscosity || level_inc > viscosity)
+ new_node_level = liquid_level + level_inc/viscosity;
+ else if (level_inc < 0)
+ new_node_level = liquid_level - 1;
+ else if (level_inc > 0)
+ new_node_level = liquid_level + 1;
+ if (new_node_level != max_node_level)
+ must_reflow.push_back(p0);
+ } else
+ new_node_level = max_node_level;
+
if (new_node_level >= 0)
new_node_content = liquid_kind;
else
new_node_content = CONTENT_AIR;
+
}
-
+
/*
check if anything has changed. if not, just continue with the next node.
*/
@@ -1727,31 +1742,36 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
((n0.param2 & LIQUID_FLOW_DOWN_MASK) == LIQUID_FLOW_DOWN_MASK)
== flowing_down)))
continue;
-
-
+
+
/*
update the current node
*/
bool flow_down_enabled = (flowing_down && ((n0.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK));
- n0.setContent(new_node_content);
- if (content_features(n0.getContent()).liquid_type == LIQUID_FLOWING) {
+ if (content_features(new_node_content).liquid_type == LIQUID_FLOWING) {
// set level to last 3 bits, flowing down bit to 4th bit
- n0.param2 |= (flowing_down ? LIQUID_FLOW_DOWN_MASK : 0x00) | (new_node_level & LIQUID_LEVEL_MASK);
+ n0.param2 = (flowing_down ? LIQUID_FLOW_DOWN_MASK : 0x00) | (new_node_level & LIQUID_LEVEL_MASK);
} else {
// set the liquid level and flow bit to 0
- n0.param2 &= ~(LIQUID_LEVEL_MASK | LIQUID_FLOW_DOWN_MASK);
+ n0.param2 = ~(LIQUID_LEVEL_MASK | LIQUID_FLOW_DOWN_MASK);
}
+ n0.setContent(new_node_content);
setNode(p0, n0);
v3s16 blockpos = getNodeBlockPos(p0);
MapBlock *block = getBlockNoCreateNoEx(blockpos);
- if(block != NULL)
+ if(block != NULL) {
modified_blocks.insert(blockpos, block);
-
+ // If node emits light, MapBlock requires lighting update
+ if(content_features(n0).light_source != 0)
+ lighting_modified_blocks[block->getPos()] = block;
+ }
+
/*
enqueue neighbors for update if neccessary
*/
switch (content_features(n0.getContent()).liquid_type) {
case LIQUID_SOURCE:
+ case LIQUID_FLOWING:
// make sure source flows into all neighboring nodes
for (u16 i = 0; i < num_flows; i++)
if (flows[i].t != NEIGHBOR_UPPER)
@@ -1765,28 +1785,12 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
for (u16 i = 0; i < num_flows; i++)
m_transforming_liquid.push_back(flows[i].p);
break;
- case LIQUID_FLOWING:
- for (u16 i = 0; i < num_flows; i++) {
- u8 flow_level = (flows[i].n.param2 & LIQUID_LEVEL_MASK);
- // liquid_level is still the ORIGINAL level of this node.
- if (flows[i].t != NEIGHBOR_UPPER && ((flow_level < liquid_level || flow_level < new_node_level) ||
- flow_down_enabled))
- m_transforming_liquid.push_back(flows[i].p);
- }
- for (u16 i = 0; i < num_airs; i++) {
- if (airs[i].t != NEIGHBOR_UPPER && (airs[i].t == NEIGHBOR_LOWER || new_node_level > 0))
- m_transforming_liquid.push_back(airs[i].p);
- }
- break;
- }
-
- loopcount++;
- //if(loopcount >= 100000)
- if(loopcount >= initial_size * 10) {
- break;
}
}
//dstream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
+ while (must_reflow.size() > 0)
+ m_transforming_liquid.push_back(must_reflow.pop_front());
+ updateLighting(lighting_modified_blocks, modified_blocks);
}
NodeMetadata* Map::getNodeMetadata(v3s16 p)
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index 9effa8ac6..0018b9919 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -1817,6 +1817,16 @@ void make_block(BlockMakeData *data)
if(noisebuf_ground_wetness.get(x,y,z) < -0.6)
vmanip.m_data[i] = MapNode(CONTENT_GRAVEL);
}
+ else if(noisebuf_ground_crumbleness.get(x,y,z) <
+ -3.0 + MYMIN(0.1 * sqrt((float)MYMAX(0, -y)), 1.5))
+ {
+ vmanip.m_data[i] = MapNode(CONTENT_LAVASOURCE);
+ for(s16 x1=-1; x1<=1; x1++)
+ for(s16 y1=-1; y1<=1; y1++)
+ for(s16 z1=-1; z1<=1; z1++)
+ data->transforming_liquid.push_back(
+ v3s16(p2d.X+x1, y+y1, p2d.Y+z1));
+ }
}
data->vmanip->m_area.add_y(em, i, -1);
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index 9a8a73295..956abe5c7 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -30,8 +30,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
ContentFeatures::~ContentFeatures()
{
- if(initial_metadata)
- delete initial_metadata;
+ delete initial_metadata;
+ delete special_material;
+ delete special_atlas;
}
void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha)
diff --git a/src/mapnode.h b/src/mapnode.h
index 389fa1c9c..4c2b92853 100644
--- a/src/mapnode.h
+++ b/src/mapnode.h
@@ -128,8 +128,8 @@ struct ContentFeatures
bool pointable;
// Player can dig these
bool diggable;
- // Player can climb these
- bool climbable;
+ // Player can climb these
+ bool climbable;
// Player can build on these
bool buildable_to;
// Whether the node has no liquid, source liquid or flowing liquid
@@ -153,12 +153,23 @@ struct ContentFeatures
content_t liquid_alternative_flowing;
// If the content is liquid, this is the source version of the liquid.
content_t liquid_alternative_source;
+ // Viscosity for fluid flow, ranging from 1 to 7, with
+ // 1 giving almost instantaneous propagation and 7 being
+ // the slowest possible
+ u8 liquid_viscosity;
+ // Used currently for flowing liquids
+ u8 vertex_alpha;
+ // Special irrlicht material, used sometimes
+ video::SMaterial *special_material;
+ AtlasPointer *special_atlas;
// Amount of light the node emits
u8 light_source;
// Digging properties for different tools
DiggingPropertiesList digging_properties;
+
+ u32 damage_per_second;
// NOTE: Move relevant properties to here from elsewhere
@@ -181,8 +192,14 @@ struct ContentFeatures
dug_item = "";
initial_metadata = NULL;
liquid_alternative_flowing = CONTENT_IGNORE;
+ liquid_alternative_source = CONTENT_IGNORE;
+ liquid_viscosity = 0;
+ vertex_alpha = 255;
+ special_material = NULL;
+ special_atlas = NULL;
light_source = 0;
digging_properties.clear();
+ damage_per_second = 0;
}
ContentFeatures()
@@ -412,6 +429,10 @@ enum LightBank
#define LIQUID_LEVEL_MASK 0x07
#define LIQUID_FLOW_DOWN_MASK 0x08
+/* maximum amount of liquid in a block */
+#define LIQUID_LEVEL_MAX LIQUID_LEVEL_MASK
+#define LIQUID_LEVEL_SOURCE (LIQUID_LEVEL_MAX+1)
+
/*
This is the stuff what the whole world consists of.
*/