summaryrefslogtreecommitdiff
path: root/src/mapnode.cpp
diff options
context:
space:
mode:
authorproller <proller@github.com>2013-07-28 17:11:59 +0400
committerproller <proller@github.com>2013-07-28 17:14:31 +0400
commit037e84d377e91f37026cb5814145bdceac135534 (patch)
tree4e74e3d60e797605353d2539d2b2fbc399b684a9 /src/mapnode.cpp
parent3aedfac9685c2d9ae8bac5a5b7e72e527f22c08d (diff)
downloadminetest-037e84d377e91f37026cb5814145bdceac135534.tar.gz
minetest-037e84d377e91f37026cb5814145bdceac135534.tar.bz2
minetest-037e84d377e91f37026cb5814145bdceac135534.zip
Better snow fall, finite liquid transform, leveled nodes api
Diffstat (limited to 'src/mapnode.cpp')
-rw-r--r--src/mapnode.cpp38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index 4707978cb..a47a48bc0 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -364,9 +364,7 @@ u8 MapNode::getMaxLevel(INodeDefManager *nodemgr) const
{
const ContentFeatures &f = nodemgr->get(*this);
// todo: after update in all games leave only if (f.param_type_2 ==
- if( f.liquid_type == LIQUID_SOURCE
- || f.liquid_type == LIQUID_FLOWING
- || f.param_type_2 == CPT2_FLOWINGLIQUID)
+ if( f.liquid_type == LIQUID_FLOWING || f.param_type_2 == CPT2_FLOWINGLIQUID)
return LIQUID_LEVEL_MAX;
if(f.leveled || f.param_type_2 == CPT2_LEVELED)
return LEVELED_MAX;
@@ -392,12 +390,9 @@ u8 MapNode::getLevel(INodeDefManager *nodemgr) const
return 0;
}
-u8 MapNode::addLevel(INodeDefManager *nodemgr, s8 add)
+u8 MapNode::setLevel(INodeDefManager *nodemgr, s8 level)
{
- s8 level = getLevel(nodemgr);
u8 rest = 0;
- if (add == 0) level = 1;
- level += add;
if (level < 1) {
setContent(CONTENT_AIR);
return 0;
@@ -406,8 +401,8 @@ u8 MapNode::addLevel(INodeDefManager *nodemgr, s8 add)
if ( f.param_type_2 == CPT2_FLOWINGLIQUID
|| f.liquid_type == LIQUID_FLOWING
|| f.liquid_type == LIQUID_SOURCE) {
- if (level >= LIQUID_LEVEL_MAX) {
- rest = level - LIQUID_LEVEL_MAX;
+ if (level >= LIQUID_LEVEL_SOURCE) {
+ rest = level - LIQUID_LEVEL_SOURCE;
setContent(nodemgr->getId(f.liquid_alternative_source));
} else {
setContent(nodemgr->getId(f.liquid_alternative_flowing));
@@ -423,6 +418,31 @@ u8 MapNode::addLevel(INodeDefManager *nodemgr, s8 add)
return rest;
}
+u8 MapNode::addLevel(INodeDefManager *nodemgr, s8 add)
+{
+ s8 level = getLevel(nodemgr);
+ if (add == 0) level = 1;
+ level += add;
+ return setLevel(nodemgr, level);
+}
+
+void MapNode::freezeMelt(INodeDefManager *ndef) {
+ u8 level_was_max = this->getMaxLevel(ndef);
+ u8 level_was = this->getLevel(ndef);
+ this->setContent(ndef->getId(ndef->get(*this).freezemelt));
+ u8 level_now_max = this->getMaxLevel(ndef);
+ if (level_was_max && level_was_max != level_now_max) {
+ u8 want = (float)level_now_max / level_was_max * level_was;
+ if (!want)
+ want = 1;
+ if (want != level_was)
+ this->setLevel(ndef, want);
+ //errorstream<<"was="<<(int)level_was<<"/"<<(int)level_was_max<<" nowm="<<(int)want<<"/"<<(int)level_now_max<< " => "<<(int)this->getLevel(ndef)<< std::endl;
+ }
+ if (this->getMaxLevel(ndef) && !this->getLevel(ndef))
+ this->addLevel(ndef);
+}
+
u32 MapNode::serializedLength(u8 version)
{
if(!ser_ver_supported(version))