Disable fall damage when "immortal" group set (#6946)
authorlisacvuk <lisacvukhome@gmail.com>
Tue, 23 Jan 2018 18:28:21 +0000 (19:28 +0100)
committerSmallJoker <SmallJoker@users.noreply.github.com>
Tue, 23 Jan 2018 18:28:21 +0000 (19:28 +0100)
src/clientenvironment.cpp
src/content_cao.cpp
src/content_cao.h

index af00586c5379f155d42f374143e966615d617b89..8de0732585efd03d460eaa90b294c3dd00fd2568 100644 (file)
@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "raycast.h"
 #include "voxelalgorithms.h"
 #include "settings.h"
+#include "content_cao.h"
 #include <algorithm>
 #include "client/renderingengine.h"
 
@@ -207,6 +208,8 @@ void ClientEnvironment::step(float dtime)
 
        //std::cout<<"Looped "<<loopcount<<" times."<<std::endl;
 
+       bool player_immortal = lplayer->getCAO() && lplayer->getCAO()->isImmortal();
+
        for (const CollisionInfo &info : player_collisions) {
                v3f speed_diff = info.new_speed - info.old_speed;;
                // Handle only fall damage
@@ -227,7 +230,7 @@ void ClientEnvironment::step(float dtime)
                        pre_factor = 1.0 + (float)addp/100.0;
                }
                float speed = pre_factor * speed_diff.getLength();
-               if (speed > tolerance) {
+               if (speed > tolerance && !player_immortal) {
                        f32 damage_f = (speed - tolerance) / BS * post_factor;
                        u8 damage = (u8)MYMIN(damage_f + 0.5, 255);
                        if (damage != 0) {
index a8b4ae2e1e830d26854d7d01bff00bab236f85f0..affa092e7fc75f5e55fb458b419dfab7dbe2da44 100644 (file)
@@ -360,6 +360,11 @@ v3f GenericCAO::getPosition()
        return pos_translator.vect_show;
 }
 
+const bool GenericCAO::isImmortal()
+{
+       return itemgroup_get(getGroups(), "immortal");
+}
+
 scene::ISceneNode* GenericCAO::getSceneNode()
 {
        if (m_meshnode) {
index 575aad24145f9adac48a4c1432f1bf96087417bf..7e946efb7ef8bcb828c1c06fc2280d004744303e 100644 (file)
@@ -124,7 +124,10 @@ public:
        {
                return ACTIVEOBJECT_TYPE_GENERIC;
        }
-
+       inline const ItemGroupList &getGroups() const
+       {
+               return m_armor_groups;
+       }
        void initialize(const std::string &data);
 
        void processInitData(const std::string &data);
@@ -143,6 +146,8 @@ public:
                return m_yaw;
        }
 
+       const bool isImmortal();
+
        scene::ISceneNode *getSceneNode();
 
        scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();