Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for different drowning damage and allow drowning in other…
… nodetypes
  • Loading branch information
BlockMen authored and PilzAdam committed Aug 6, 2013
1 parent ba65e2a commit 7b13d11
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions builtin/item.lua
Expand Up @@ -490,6 +490,7 @@ minetest.nodedef_default = {
liquid_alternative_flowing = "",
liquid_alternative_source = "",
liquid_viscosity = 0,
drowning = 0,
light_source = 0,
damage_per_second = 0,
selection_box = {type="regular"},
Expand Down
2 changes: 1 addition & 1 deletion doc/lua_api.txt
Expand Up @@ -1991,7 +1991,7 @@ Node definition (register_node)
freezemelt = "", -- water for snow/ice, ice/snow for water
leveled = 0, -- Block contain level in param2. value - default level, used for snow. Dont forget use "leveled" type nodebox
liquid_range = 8, -- number of flowing nodes arround source (max. 8)
drowning = true, -- Player will drown in these
drowning = 0, -- Player will take this amount of damage if no bubbles are left
two or more sources nearly?
light_source = 0, -- Amount of light emitted by node
damage_per_second = 0, -- If player is inside node, this damage is caused
Expand Down
4 changes: 4 additions & 0 deletions games/minimal/mods/default/init.lua
Expand Up @@ -1001,6 +1001,7 @@ minetest.register_node("default:water_flowing", {
pointable = false,
diggable = false,
buildable_to = true,
drowning = 1,
liquidtype = "flowing",
liquid_alternative_flowing = "default:water_flowing",
liquid_alternative_source = "default:water_source",
Expand All @@ -1024,6 +1025,7 @@ minetest.register_node("default:water_source", {
pointable = false,
diggable = false,
buildable_to = true,
drowning = 1,
liquidtype = "source",
liquid_alternative_flowing = "default:water_flowing",
liquid_alternative_source = "default:water_source",
Expand Down Expand Up @@ -1055,6 +1057,7 @@ minetest.register_node("default:lava_flowing", {
pointable = false,
diggable = false,
buildable_to = true,
drowning = 1,
liquidtype = "flowing",
liquid_alternative_flowing = "default:lava_flowing",
liquid_alternative_source = "default:lava_source",
Expand Down Expand Up @@ -1082,6 +1085,7 @@ minetest.register_node("default:lava_source", {
pointable = false,
diggable = false,
buildable_to = true,
drowning = 1,
liquidtype = "source",
liquid_alternative_flowing = "default:lava_flowing",
liquid_alternative_source = "default:lava_source",
Expand Down
9 changes: 5 additions & 4 deletions src/environment.cpp
Expand Up @@ -2243,7 +2243,8 @@ void ClientEnvironment::step(float dtime)
v3s16 p = floatToInt(pf + v3f(0, BS*1.6, 0), BS);
MapNode n = m_map->getNodeNoEx(p);
ContentFeatures c = m_gamedef->ndef()->get(n);
if(c.isLiquid() && c.drowning && lplayer->hp > 0){
u8 drowning_damage = c.drowning;
if(drowning_damage > 0 && lplayer->hp > 0){
u16 breath = lplayer->getBreath();
if(breath > 10){
breath = 11;
Expand All @@ -2255,8 +2256,8 @@ void ClientEnvironment::step(float dtime)
updateLocalPlayerBreath(breath);
}

if(lplayer->getBreath() == 0){
damageLocalPlayer(1, true);
if(lplayer->getBreath() == 0 && drowning_damage > 0){
damageLocalPlayer(drowning_damage, true);
}
}
if(m_breathing_interval.step(dtime, 0.5))
Expand All @@ -2270,7 +2271,7 @@ void ClientEnvironment::step(float dtime)
if (!lplayer->hp){
lplayer->setBreath(11);
}
else if(!c.isLiquid() || !c.drowning){
else if(c.drowning == 0){
u16 breath = lplayer->getBreath();
if(breath <= 10){
breath += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/nodedef.cpp
Expand Up @@ -220,7 +220,7 @@ void ContentFeatures::reset()
liquid_renewable = true;
freezemelt = "";
liquid_range = LIQUID_LEVEL_MAX+1;
drowning = true;
drowning = 0;
light_source = 0;
damage_per_second = 0;
node_box = NodeBox();
Expand Down
2 changes: 1 addition & 1 deletion src/nodedef.h
Expand Up @@ -228,7 +228,7 @@ struct ContentFeatures
std::string freezemelt;
// Number of flowing liquids surrounding source
u8 liquid_range;
bool drowning;
u8 drowning;
// Amount of light the node emits
u8 light_source;
u32 damage_per_second;
Expand Down
3 changes: 2 additions & 1 deletion src/script/common/c_content.cpp
Expand Up @@ -400,7 +400,8 @@ ContentFeatures read_content_features(lua_State *L, int index)

getboolfield(L, index, "liquid_renewable", f.liquid_renewable);
getstringfield(L, index, "freezemelt", f.freezemelt);
getboolfield(L, index, "drowning", f.drowning);
f.drowning = getintfield_default(L, index,
"drowning", f.drowning);
// Amount of light the node emits
f.light_source = getintfield_default(L, index,
"light_source", f.light_source);
Expand Down

0 comments on commit 7b13d11

Please sign in to comment.