Add support for entities to automatic face movement direction
authorsapier <Sapier at GMX dot net>
Wed, 31 Jul 2013 15:29:25 +0000 (17:29 +0200)
committerPilzAdam <pilzadam@minetest.net>
Tue, 13 Aug 2013 21:48:47 +0000 (23:48 +0200)
doc/lua_api.txt
src/clientserver.h
src/content_cao.cpp
src/content_sao.cpp
src/object_properties.cpp
src/object_properties.h
src/script/common/c_content.cpp

index 3dfb67157db909cd2456dd6220d404152ed4ee93..5244ff22156acad2a49ab36874be659b2bbe66af 100644 (file)
@@ -1863,6 +1863,7 @@ Object Properties
     makes_footstep_sound = false,
     automatic_rotate = false,
     stepheight = 0,
+    automatic_face_movement_dir = false,
 }
 
 Entity definition (register_entity)
index 264da5179e340ced795d2751662302a5695b69cb..ebfe7f3c79d87fdf0be40a12024768d595b4a6b9 100644 (file)
@@ -102,6 +102,7 @@ SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed);
                drowning, leveled and liquid_range added to ContentFeatures
                stepheight and collideWithObjects added to object properties
                version, heat and humidity transfer in MapBock
+               added new property to entities automatic_face_movement_dir
 */
 
 #define LATEST_PROTOCOL_VERSION 21
index bbee0bc8350243ddb182cd41107495361ab79a90..20f5fd3db4781a1d50fa06e05847dde224b85958 100644 (file)
@@ -1210,6 +1210,11 @@ public:
                        m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI;
                        updateNodePos();
                }
+
+               if (getParent() == NULL && m_prop.automatic_face_movement_dir){
+                       m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI;
+                       updateNodePos();
+               }
        }
 
        void updateTexturePos()
index ed660cf1006139cbc21379083669d3df095adf87..f3ccd6db0fe45de38374b61d77fd71ec78e1253b 100644 (file)
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "cpp_api/scriptapi.h"
 #include "genericobject.h"
 #include "util/serialize.h"
+#include "util/mathconstants.h"
 
 std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
 
@@ -522,6 +523,10 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
                                        * dtime * m_acceleration;
                        m_velocity += dtime * m_acceleration;
                }
+
+               if(m_prop.automatic_face_movement_dir){
+                       m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI;
+               }
        }
 
        if(m_registered){
index 1602f03f20312faff3873cb3919b333f89b961a4..7fad25cceda3c84a8aff4abc01395e2508570768 100644 (file)
@@ -40,7 +40,8 @@ ObjectProperties::ObjectProperties():
        is_visible(true),
        makes_footstep_sound(false),
        automatic_rotate(0),
-       stepheight(0)
+       stepheight(0),
+       automatic_face_movement_dir(false)
 {
        textures.push_back("unknown_object.png");
        colors.push_back(video::SColor(255,255,255,255));
@@ -102,6 +103,7 @@ void ObjectProperties::serialize(std::ostream &os) const
        }
        writeU8(os, collideWithObjects);
        writeF1000(os,stepheight);
+       writeU8(os, automatic_face_movement_dir);
        // Add stuff only at the bottom.
        // Never remove anything, because we don't want new versions of this
 }
@@ -136,6 +138,7 @@ void ObjectProperties::deSerialize(std::istream &is)
                        }
                        collideWithObjects = readU8(is);
                        stepheight = readF1000(is);
+                       automatic_face_movement_dir = readU8(is);
                }catch(SerializationError &e){}
        }
        else
index e8188cb604dbd96ca0c2a915573f9729fd549417..edc9c39d670dbd0f8bf715408f9d59123eddc06c 100644 (file)
@@ -45,6 +45,7 @@ struct ObjectProperties
        bool makes_footstep_sound;
        float automatic_rotate;
        f32 stepheight;
+       bool automatic_face_movement_dir;
 
 
        ObjectProperties();
index ca7c7fde934bccf4d43e5d592fb4aed5f24729db..cb2b0e737ae68b96c292de4fd1e16aaa22123552 100644 (file)
@@ -190,6 +190,7 @@ void read_object_properties(lua_State *L, int index,
        getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
        getfloatfield(L, -1, "stepheight", prop->stepheight);
        prop->stepheight*=BS;
+       getboolfield(L, -1, "automatic_face_movement_dir", prop->automatic_face_movement_dir);
 }
 
 /******************************************************************************/