From fc571ad46df8f3dcc04745bc55d9ca6e1e82ed87 Mon Sep 17 00:00:00 2001 From: sapier Date: Wed, 31 Jul 2013 17:29:25 +0200 Subject: [PATCH] Add support for entities to automatic face movement direction --- doc/lua_api.txt | 1 + src/clientserver.h | 1 + src/content_cao.cpp | 5 +++++ src/content_sao.cpp | 5 +++++ src/object_properties.cpp | 5 ++++- src/object_properties.h | 1 + src/script/common/c_content.cpp | 1 + 7 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 3dfb6715..5244ff22 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1863,6 +1863,7 @@ Object Properties makes_footstep_sound = false, automatic_rotate = false, stepheight = 0, + automatic_face_movement_dir = false, } Entity definition (register_entity) diff --git a/src/clientserver.h b/src/clientserver.h index 264da517..ebfe7f3c 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -102,6 +102,7 @@ SharedBuffer 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 diff --git a/src/content_cao.cpp b/src/content_cao.cpp index bbee0bc8..20f5fd3d 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -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() diff --git a/src/content_sao.cpp b/src/content_sao.cpp index ed660cf1..f3ccd6db 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -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 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){ diff --git a/src/object_properties.cpp b/src/object_properties.cpp index 1602f03f..7fad25cc 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -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 diff --git a/src/object_properties.h b/src/object_properties.h index e8188cb6..edc9c39d 100644 --- a/src/object_properties.h +++ b/src/object_properties.h @@ -45,6 +45,7 @@ struct ObjectProperties bool makes_footstep_sound; float automatic_rotate; f32 stepheight; + bool automatic_face_movement_dir; ObjectProperties(); diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index ca7c7fde..cb2b0e73 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -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); } /******************************************************************************/ -- 2.30.2