Add support for entities to automatic face movement direction

This commit is contained in:
sapier 2013-07-31 17:29:25 +02:00 committed by PilzAdam
parent d718b0b34e
commit fc571ad46d
7 changed files with 18 additions and 1 deletions

View File

@ -1863,6 +1863,7 @@ Object Properties
makes_footstep_sound = false, makes_footstep_sound = false,
automatic_rotate = false, automatic_rotate = false,
stepheight = 0, stepheight = 0,
automatic_face_movement_dir = false,
} }
Entity definition (register_entity) Entity definition (register_entity)

View 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 drowning, leveled and liquid_range added to ContentFeatures
stepheight and collideWithObjects added to object properties stepheight and collideWithObjects added to object properties
version, heat and humidity transfer in MapBock version, heat and humidity transfer in MapBock
added new property to entities automatic_face_movement_dir
*/ */
#define LATEST_PROTOCOL_VERSION 21 #define LATEST_PROTOCOL_VERSION 21

View File

@ -1210,6 +1210,11 @@ public:
m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI; m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI;
updateNodePos(); 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() void updateTexturePos()

View File

@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "cpp_api/scriptapi.h" #include "cpp_api/scriptapi.h"
#include "genericobject.h" #include "genericobject.h"
#include "util/serialize.h" #include "util/serialize.h"
#include "util/mathconstants.h"
std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types; std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
@ -522,6 +523,10 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
* dtime * m_acceleration; * dtime * m_acceleration;
m_velocity += 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){ if(m_registered){

View File

@ -40,7 +40,8 @@ ObjectProperties::ObjectProperties():
is_visible(true), is_visible(true),
makes_footstep_sound(false), makes_footstep_sound(false),
automatic_rotate(0), automatic_rotate(0),
stepheight(0) stepheight(0),
automatic_face_movement_dir(false)
{ {
textures.push_back("unknown_object.png"); textures.push_back("unknown_object.png");
colors.push_back(video::SColor(255,255,255,255)); colors.push_back(video::SColor(255,255,255,255));
@ -102,6 +103,7 @@ void ObjectProperties::serialize(std::ostream &os) const
} }
writeU8(os, collideWithObjects); writeU8(os, collideWithObjects);
writeF1000(os,stepheight); writeF1000(os,stepheight);
writeU8(os, automatic_face_movement_dir);
// Add stuff only at the bottom. // Add stuff only at the bottom.
// Never remove anything, because we don't want new versions of this // 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); collideWithObjects = readU8(is);
stepheight = readF1000(is); stepheight = readF1000(is);
automatic_face_movement_dir = readU8(is);
}catch(SerializationError &e){} }catch(SerializationError &e){}
} }
else else

View File

@ -45,6 +45,7 @@ struct ObjectProperties
bool makes_footstep_sound; bool makes_footstep_sound;
float automatic_rotate; float automatic_rotate;
f32 stepheight; f32 stepheight;
bool automatic_face_movement_dir;
ObjectProperties(); ObjectProperties();

View 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, "automatic_rotate", prop->automatic_rotate);
getfloatfield(L, -1, "stepheight", prop->stepheight); getfloatfield(L, -1, "stepheight", prop->stepheight);
prop->stepheight*=BS; prop->stepheight*=BS;
getboolfield(L, -1, "automatic_face_movement_dir", prop->automatic_face_movement_dir);
} }
/******************************************************************************/ /******************************************************************************/