From d19c8b815dc137ea4c19e5f5a54c40693059b455 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Fri, 19 Jul 2013 19:50:33 +0200 Subject: Add set_breath and get_breath to lua API. --- src/environment.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'src/environment.cpp') diff --git a/src/environment.cpp b/src/environment.cpp index cd8783984..57fdfd7e5 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -2242,15 +2242,19 @@ 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){ - if(lplayer->breath > 10) - lplayer->breath = 11; - if(lplayer->breath > 0) - lplayer->breath -= 1; + if(c.isLiquid() && c.drowning && lplayer->hp > 0){ + u16 breath = lplayer->getBreath(); + if(breath > 10){ + breath = 11; + } + if(breath > 0){ + breath -= 1; + } + lplayer->setBreath(breath); + updateLocalPlayerBreath(breath); } - if(lplayer->breath == 0){ + if(lplayer->getBreath() == 0){ damageLocalPlayer(1, true); } } @@ -2262,10 +2266,16 @@ 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){ - if(lplayer->breath <= 10) - lplayer->breath += 1; + if (!lplayer->hp){ + lplayer->setBreath(11); + } + else if(!c.isLiquid() || !c.drowning){ + u16 breath = lplayer->getBreath(); + if(breath <= 10){ + breath += 1; + lplayer->setBreath(breath); + updateLocalPlayerBreath(breath); + } } } @@ -2528,6 +2538,14 @@ void ClientEnvironment::damageLocalPlayer(u8 damage, bool handle_hp) m_client_event_queue.push_back(event); } +void ClientEnvironment::updateLocalPlayerBreath(u16 breath) +{ + ClientEnvEvent event; + event.type = CEE_PLAYER_BREATH; + event.player_breath.amount = breath; + m_client_event_queue.push_back(event); +} + /* Client likes to call these */ -- cgit v1.2.3