From 8f42a8be0c760322207287e50b624bd3d388a2e1 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 15 Aug 2011 02:04:56 +0300 Subject: lava! --- src/content_mapnode.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) (limited to 'src/content_mapnode.cpp') diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index b164033db..3c1353467 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -372,6 +372,21 @@ void content_mapnode_init() f->liquid_type = LIQUID_FLOWING; f->liquid_alternative_flowing = CONTENT_WATER; f->liquid_alternative_source = CONTENT_WATERSOURCE; + f->vertex_alpha = 160; + 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); @@ -389,7 +404,7 @@ void content_mapnode_init() if(g_texturesource) t.texture = g_texturesource->getTexture("water.png"); - t.alpha = WATER_ALPHA; + t.alpha = 160; t.material_type = MATERIAL_ALPHA_VERTEX; t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING; f->setAllTiles(t); @@ -404,6 +419,98 @@ 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->vertex_alpha = 160; + 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; + 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_VERTEX_ALPHA; + 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; + 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_VERTEX_ALPHA; + 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); -- cgit v1.2.3 From 472585a7e8e511e7cc210ad8e2c17cad9dfeb186 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 15 Aug 2011 11:49:39 +0300 Subject: tuned lava/universal damage code --- src/content_mapnode.cpp | 2 ++ src/environment.cpp | 24 +++++++++++++++++------- src/mapnode.h | 3 +++ 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src/content_mapnode.cpp') diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index 3c1353467..f3d5b9f59 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -449,6 +449,7 @@ void content_mapnode_init() f->liquid_type = LIQUID_FLOWING; f->liquid_alternative_flowing = CONTENT_LAVA; f->liquid_alternative_source = CONTENT_LAVASOURCE; + f->damage_per_second = 4*2; if(f->special_material == NULL && g_texturesource) { // Flowing lava material @@ -496,6 +497,7 @@ void content_mapnode_init() f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->liquid_alternative_flowing = CONTENT_LAVA; f->liquid_alternative_source = CONTENT_LAVASOURCE; + f->damage_per_second = 4*2; if(f->special_material == NULL && g_texturesource) { // Flowing lava material diff --git a/src/environment.cpp b/src/environment.cpp index 05efe9eea..d6ff4d826 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1638,18 +1638,28 @@ void ClientEnvironment::step(float dtime) if(m_lava_hurt_interval.step(dtime, 1.0)) { v3f pf = lplayer->getPosition(); - v3s16 p1 = floatToInt(pf + v3f(0, BS*0.0, 0), BS); + + // 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*1.5, 0), BS); + v3s16 p2 = floatToInt(pf + v3f(0, BS*0.8, 0), BS); MapNode n2 = m_map->getNodeNoEx(p2); - if(n1.getContent() == CONTENT_LAVA || - n1.getContent() == CONTENT_LAVASOURCE || - n2.getContent() == CONTENT_LAVA || - n2.getContent() == CONTENT_LAVASOURCE) + 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 = 4*2; // 4 hearts + event.player_damage.amount = damage_per_second; m_client_event_queue.push_back(event); } } diff --git a/src/mapnode.h b/src/mapnode.h index 7ac050ef0..3101a9fc1 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -164,6 +164,8 @@ struct ContentFeatures // Digging properties for different tools DiggingPropertiesList digging_properties; + + u32 damage_per_second; // NOTE: Move relevant properties to here from elsewhere @@ -192,6 +194,7 @@ struct ContentFeatures special_atlas = NULL; light_source = 0; digging_properties.clear(); + damage_per_second = 0; } ContentFeatures() -- cgit v1.2.3 From 8ab77f41531ab325a9dc027070e317d3651888dd Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 15 Aug 2011 11:51:33 +0300 Subject: Added #define WATER_ALPHA in content_mapnode.cpp --- src/content_mapnode.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/content_mapnode.cpp') diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index f3d5b9f59..a3c8d4b0a 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapnode.h" #include "content_nodemeta.h" +#define WATER_ALPHA 160 + // 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,7 +374,7 @@ void content_mapnode_init() f->liquid_type = LIQUID_FLOWING; f->liquid_alternative_flowing = CONTENT_WATER; f->liquid_alternative_source = CONTENT_WATERSOURCE; - f->vertex_alpha = 160; + f->vertex_alpha = WATER_ALPHA; if(f->special_material == NULL && g_texturesource) { // Flowing water material @@ -404,7 +406,7 @@ void content_mapnode_init() if(g_texturesource) t.texture = g_texturesource->getTexture("water.png"); - t.alpha = 160; + t.alpha = WATER_ALPHA; t.material_type = MATERIAL_ALPHA_VERTEX; t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING; f->setAllTiles(t); @@ -419,7 +421,7 @@ 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->vertex_alpha = 160; + f->vertex_alpha = WATER_ALPHA; if(f->special_material == NULL && g_texturesource) { // Flowing water material -- cgit v1.2.3 From 0c7e7f49980851c4290817dae7a9c1cdc4a93b65 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 15 Aug 2011 12:08:41 +0300 Subject: Non-vertex-alpha texture material for lava --- src/content_mapnode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/content_mapnode.cpp') diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index a3c8d4b0a..7174a8a4b 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -460,7 +460,7 @@ void content_mapnode_init() 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; + f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; AtlasPointer *pa_lava1 = new AtlasPointer( g_texturesource->getTexture( g_texturesource->getTextureId("lava.png"))); @@ -508,7 +508,7 @@ void content_mapnode_init() 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; + f->special_material->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; AtlasPointer *pa_lava1 = new AtlasPointer( g_texturesource->getTexture( g_texturesource->getTextureId("lava.png"))); -- cgit v1.2.3