diff options
author | PilzAdam <pilzadam@minetest.net> | 2013-06-19 14:30:22 +0000 |
---|---|---|
committer | PilzAdam <pilzadam@minetest.net> | 2013-06-19 15:47:00 +0000 |
commit | 53066024f6a91d5f83241b379b94d8557d43a646 (patch) | |
tree | c785c98f2cc0b45a2430e0e6a374676cd0a175c4 /src/environment.cpp | |
parent | e65ac4d626f69656c57c07e4df1a1113a014f34a (diff) | |
download | minetest-53066024f6a91d5f83241b379b94d8557d43a646.tar.gz minetest-53066024f6a91d5f83241b379b94d8557d43a646.tar.bz2 minetest-53066024f6a91d5f83241b379b94d8557d43a646.zip |
Add drowning
Diffstat (limited to 'src/environment.cpp')
-rw-r--r-- | src/environment.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/environment.cpp b/src/environment.cpp index a97a9bd08..99da5190c 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -2227,7 +2227,45 @@ void ClientEnvironment::step(float dtime) damageLocalPlayer(damage_per_second, true); } } - + + /* + Drowning + */ + if(m_drowning_interval.step(dtime, 2.0)) + { + v3f pf = lplayer->getPosition(); + + // head + 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){ + if(lplayer->breath > 10) + lplayer->breath = 11; + if(lplayer->breath > 0) + lplayer->breath -= 1; + } + + if(lplayer->breath == 0){ + damageLocalPlayer(1, true); + } + } + if(m_breathing_interval.step(dtime, 0.5)) + { + v3f pf = lplayer->getPosition(); + + // head + 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){ + if(lplayer->breath <= 10) + lplayer->breath += 1; + } + } + /* Stuff that can be done in an arbitarily large dtime */ |