Add support for different drowning damage and allow drowning in other nodetypes

stable-0.4
BlockMen 2013-08-01 18:36:11 +02:00 committed by PilzAdam
parent ba65e2ae6c
commit 7b13d119ed
7 changed files with 15 additions and 8 deletions

View File

@ -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"},

View File

@ -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

View File

@ -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",
@ -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",
@ -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",
@ -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",

View File

@ -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;
@ -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))
@ -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;

View File

@ -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();

View File

@ -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;

View File

@ -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);