291 changes: 170 additions & 121 deletions src/map.cpp

Large diffs are not rendered by default.

61 changes: 34 additions & 27 deletions src/mapnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,12 @@ static std::vector<aabb3f> transformNodeBox(const MapNode &n,
}
else // NODEBOX_REGULAR
{
boxes.push_back(aabb3f(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2));
const ContentFeatures &f = nodemgr->get(n);
float top = BS/2;
if (f.param_type_2 == CPT2_LEVELED || f.param_type_2 == CPT2_FLOWINGLIQUID)
top = -BS/2 + BS*((float)1/f.getMaxLevel()) * n.getLevel(nodemgr);

boxes.push_back(aabb3f(-BS/2,-BS/2,-BS/2,BS/2,top,BS/2));
}
return boxes;
}
Expand All @@ -362,31 +367,30 @@ std::vector<aabb3f> MapNode::getSelectionBoxes(INodeDefManager *nodemgr) const

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_FLOWING || f.param_type_2 == CPT2_FLOWINGLIQUID)
return LIQUID_LEVEL_MAX;
if(f.leveled || f.param_type_2 == CPT2_LEVELED)
return LEVELED_MAX;
return 0;
return nodemgr->get(*this).getMaxLevel();
}

u8 MapNode::getLevel(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)
if (f.param_type_2 == CPT2_LEVELED) {
u8 level = getParam2() & LEVELED_MASK;
if(level)
return level;
}
if(f.leveled) {
if(f.leveled > LEVELED_MAX)
return LEVELED_MAX;
//if(f.leveled > f.getMaxLevel()) return f.getMaxLevel();
return f.leveled; //default
}
if(f.liquid_type == LIQUID_SOURCE) {
if (nodemgr->get(nodemgr->getId(f.liquid_alternative_flowing)).param_type_2 == CPT2_LEVELED)
return LEVELED_MAX;
return LIQUID_LEVEL_SOURCE;
if (f.param_type_2 == CPT2_FLOWINGLIQUID)
return getParam2() & LIQUID_LEVEL_MASK;
if(f.liquid_type == LIQUID_FLOWING) // can remove if all param_type_2 setted
return getParam2() & LIQUID_LEVEL_MASK;
if(f.leveled || f.param_type_2 == CPT2_LEVELED) {
u8 level = getParam2() & LEVELED_MASK;
if(level) return level;
if(f.leveled > LEVELED_MAX) return LEVELED_MAX;
return f.leveled; //default
}
if (f.param_type_2 == CPT2_FLOWINGLIQUID || f.liquid_type == LIQUID_FLOWING) //remove liquid_type later
return getParam2() & LIQUID_LEVEL_MASK;
return 0;
}

Expand All @@ -398,7 +402,17 @@ u8 MapNode::setLevel(INodeDefManager *nodemgr, s8 level)
return 0;
}
const ContentFeatures &f = nodemgr->get(*this);
if ( f.param_type_2 == CPT2_FLOWINGLIQUID
if (f.param_type_2 == CPT2_LEVELED) {
if (level > f.getMaxLevel()) {
rest = level - f.getMaxLevel();
level = f.getMaxLevel();
}
if (level == f.getMaxLevel() && !f.liquid_alternative_source.empty()) {
setContent(nodemgr->getId(f.liquid_alternative_source));
} else {
setParam2(level & LEVELED_MASK);
}
} else if (f.param_type_2 == CPT2_FLOWINGLIQUID
|| f.liquid_type == LIQUID_FLOWING
|| f.liquid_type == LIQUID_SOURCE) {
if (level >= LIQUID_LEVEL_SOURCE) {
Expand All @@ -408,12 +422,6 @@ u8 MapNode::setLevel(INodeDefManager *nodemgr, s8 level)
setContent(nodemgr->getId(f.liquid_alternative_flowing));
setParam2(level & LIQUID_LEVEL_MASK);
}
} else if (f.leveled || f.param_type_2 == CPT2_LEVELED) {
if (level > LEVELED_MAX) {
rest = level - LEVELED_MAX;
level = LEVELED_MAX;
}
setParam2(level & LEVELED_MASK);
}
return rest;
}
Expand All @@ -437,7 +445,6 @@ void MapNode::freezeMelt(INodeDefManager *ndef) {
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);
Expand Down
4 changes: 2 additions & 2 deletions src/mapnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ enum Rotation {
Masks for MapNode.param2 of flowing liquids
*/
#define LIQUID_LEVEL_MASK 0x07
#define LIQUID_FLOW_DOWN_MASK 0x08
#define LIQUID_FLOW_DOWN_MASK 0x40 //0b01000000 // only for _flowing liquid

//#define LIQUID_LEVEL_MASK 0x3f // better finite water
//#define LIQUID_FLOW_DOWN_MASK 0x40 // not used when finite water
Expand All @@ -102,7 +102,7 @@ enum Rotation {
#define LIQUID_LEVEL_MAX LIQUID_LEVEL_MASK
#define LIQUID_LEVEL_SOURCE (LIQUID_LEVEL_MAX+1)

#define LIQUID_INFINITY_MASK 0x80 //0b10000000
#define LIQUID_INFINITY_MASK 0x80 //0b10000000 // only for _source liquid

// mask for param2, now as for liquid
#define LEVELED_MASK 0x3F
Expand Down
5 changes: 2 additions & 3 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ void ContentFeatures::reset()
liquid_viscosity = 0;
liquid_renewable = true;
freezemelt = "";
liquid_range = LIQUID_LEVEL_MAX+1;
drowning = 0;
light_source = 0;
damage_per_second = 0;
Expand Down Expand Up @@ -289,7 +288,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version)
writeU8(os, rightclickable);
writeU8(os, drowning);
writeU8(os, leveled);
writeU8(os, liquid_range);
writeU8(os, 0/*liquid_range*/);
// Stuff below should be moved to correct place in a version that otherwise changes
// the protocol version
}
Expand Down Expand Up @@ -353,7 +352,7 @@ void ContentFeatures::deSerialize(std::istream &is)
rightclickable = readU8(is);
drowning = readU8(is);
leveled = readU8(is);
liquid_range = readU8(is);
/*liquid_range =*/ readU8(is);
// If you add anything here, insert it primarily inside the try-catch
// block to not need to increase the version.
try{
Expand Down
11 changes: 10 additions & 1 deletion src/nodedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ struct ContentFeatures
// Ice for water, water for ice
std::string freezemelt;
// Number of flowing liquids surrounding source
u8 liquid_range;
u8 drowning;
// Amount of light the node emits
u8 light_source;
Expand Down Expand Up @@ -267,6 +266,16 @@ struct ContentFeatures
if(!isLiquid() || !f.isLiquid()) return false;
return (liquid_alternative_flowing == f.liquid_alternative_flowing);
}
u8 getMaxLevel() const{
if(param_type_2 == CPT2_LEVELED && liquid_type == LIQUID_FLOWING && leveled)
return leveled;
if(leveled || param_type_2 == CPT2_LEVELED)
return LEVELED_MAX;
if(param_type_2 == CPT2_FLOWINGLIQUID || liquid_type == LIQUID_FLOWING) //remove liquid_type
return LIQUID_LEVEL_SOURCE;
return 0;
}

};

class INodeDefManager
Expand Down
3 changes: 1 addition & 2 deletions src/script/common/c_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ ContentFeatures read_content_features(lua_State *L, int index)
// the slowest possible
f.liquid_viscosity = getintfield_default(L, index,
"liquid_viscosity", f.liquid_viscosity);
f.liquid_range = getintfield_default(L, index,
"liquid_range", f.liquid_range);

f.leveled = getintfield_default(L, index, "leveled", f.leveled);

getboolfield(L, index, "liquid_renewable", f.liquid_renewable);
Expand Down