]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_sao.cpp
Add offset to automatic_face_movement_dir
[dragonfireclient.git] / src / content_sao.cpp
index ed660cf1006139cbc21379083669d3df095adf87..85ab8d307abe4bb4e36682eea48f92ffe6a6c8bc 100644 (file)
@@ -27,9 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "tool.h" // For ToolCapabilities
 #include "gamedef.h"
 #include "player.h"
-#include "cpp_api/scriptapi.h"
+#include "scripting_game.h"
 #include "genericobject.h"
 #include "util/serialize.h"
+#include "util/mathconstants.h"
 
 std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
 
@@ -398,7 +399,7 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
 LuaEntitySAO::~LuaEntitySAO()
 {
        if(m_registered){
-               ENV_TO_SA(m_env)->luaentity_Remove(m_id);
+               m_env->getScriptIface()->luaentity_Remove(m_id);
        }
 }
 
@@ -407,15 +408,18 @@ void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
        ServerActiveObject::addedToEnvironment(dtime_s);
        
        // Create entity from name
-       m_registered = ENV_TO_SA(m_env)->luaentity_Add(m_id, m_init_name.c_str());
+       m_registered = m_env->getScriptIface()->
+               luaentity_Add(m_id, m_init_name.c_str());
        
        if(m_registered){
                // Get properties
-               ENV_TO_SA(m_env)->luaentity_GetProperties(m_id, &m_prop);
+               m_env->getScriptIface()->
+                       luaentity_GetProperties(m_id, &m_prop);
                // Initialize HP from properties
                m_hp = m_prop.hp_max;
                // Activate entity, supplying serialized state
-               ENV_TO_SA(m_env)->luaentity_Activate(m_id, m_init_state.c_str(), dtime_s);
+               m_env->getScriptIface()->
+                       luaentity_Activate(m_id, m_init_state.c_str(), dtime_s);
        }
 }
 
@@ -522,10 +526,15 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
                                        * dtime * m_acceleration;
                        m_velocity += dtime * m_acceleration;
                }
+
+               if((m_prop.automatic_face_movement_dir) &&
+                               (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)){
+                       m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI + m_prop.automatic_face_movement_dir_offset;
+               }
        }
 
        if(m_registered){
-               ENV_TO_SA(m_env)->luaentity_Step(m_id, dtime);
+               m_env->getScriptIface()->luaentity_Step(m_id, dtime);
        }
 
        if(send_recommended == false)
@@ -635,7 +644,8 @@ std::string LuaEntitySAO::getStaticData()
        os<<serializeString(m_init_name);
        // state
        if(m_registered){
-               std::string state = ENV_TO_SA(m_env)->luaentity_GetStaticdata(m_id);
+               std::string state = m_env->getScriptIface()->
+                       luaentity_GetStaticdata(m_id);
                os<<serializeLongString(state);
        } else {
                os<<serializeLongString(m_init_state);
@@ -702,7 +712,7 @@ int LuaEntitySAO::punch(v3f dir,
                        m_removed = true;
        }
 
-       ENV_TO_SA(m_env)->luaentity_Punch(m_id, puncher,
+       m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
                        time_from_last_punch, toolcap, dir);
 
        return result.wear;
@@ -715,7 +725,7 @@ void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
        // It's best that attachments cannot be clicked
        if(isAttached())
                return;
-       ENV_TO_SA(m_env)->luaentity_Rightclick(m_id, clicker);
+       m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker);
 }
 
 void LuaEntitySAO::setPos(v3f pos)
@@ -933,6 +943,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
        m_player(player_),
        m_peer_id(peer_id_),
        m_inventory(NULL),
+       m_damage(0),
        m_last_good_position(0,0,0),
        m_time_from_last_punch(0),
        m_nocheat_dig_pos(32767, 32767, 32767),
@@ -1289,14 +1300,6 @@ int PlayerSAO::punch(v3f dir,
 
        setHP(getHP() - hitparams.hp);
 
-       if(hitparams.hp != 0)
-       {
-               std::string str = gob_cmd_punched(hitparams.hp, getHP());
-               // create message and add to list
-               ActiveObjectMessage aom(getId(), true, str);
-               m_messages_out.push_back(aom);
-       }
-
        return hitparams.wear;
 }
 
@@ -1309,6 +1312,13 @@ s16 PlayerSAO::getHP() const
        return m_player->hp;
 }
 
+s16 PlayerSAO::readDamage()
+{
+       s16 damage = m_damage;
+       m_damage = 0;
+       return damage;
+}
+
 void PlayerSAO::setHP(s16 hp)
 {
        s16 oldhp = m_player->hp;
@@ -1326,19 +1336,15 @@ void PlayerSAO::setHP(s16 hp)
 
        m_player->hp = hp;
 
-       if(hp != oldhp)
+       if(hp != oldhp) {
                m_hp_not_sent = true;
+               if(oldhp > hp)
+                       m_damage += oldhp - hp;
+       }
 
-       // On death or reincarnation send an active object message
+       // Update properties on death
        if((hp == 0) != (oldhp == 0))
-       {
-               // Will send new is_visible value based on (getHP()!=0)
                m_properties_sent = false;
-               // Send new HP
-               std::string str = gob_cmd_punched(0, getHP());
-               ActiveObjectMessage aom(getId(), true, str);
-               m_messages_out.push_back(aom);
-       }
 }
 
 u16 PlayerSAO::getBreath() const