]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_sao.cpp
Write common mapgen params to map_meta.txt on world initialization
[dragonfireclient.git] / src / content_sao.cpp
index 347e8892949c5d48fcc0898dc33f81dd9d6e3d02..d4b3079ec2cc0fe7c30b587d9ba611dd993ee921 100644 (file)
@@ -18,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "content_sao.h"
+#include "util/serialize.h"
+#include "util/mathconstants.h"
 #include "collision.h"
 #include "environment.h"
 #include "settings.h"
@@ -29,8 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "player.h"
 #include "scripting_game.h"
 #include "genericobject.h"
-#include "util/serialize.h"
-#include "util/mathconstants.h"
+#include "log.h"
 
 std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
 
@@ -52,7 +53,7 @@ class DummyLoadSAO : public ServerActiveObject
        // And never save to disk
        bool isStaticAllowed() const
        { return false; }
-       
+
        static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
                        const std::string &data)
        {
@@ -98,7 +99,7 @@ class TestSAO : public ServerActiveObject
        }
        u8 getType() const
        { return ACTIVEOBJECT_TYPE_TEST; }
-       
+
        static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
                        const std::string &data)
        {
@@ -169,7 +170,7 @@ class ItemSAO : public ServerActiveObject
 public:
        u8 getType() const
        { return ACTIVEOBJECT_TYPE_ITEM; }
-       
+
        float getMinimumSavedMovement()
        { return 0.1*BS; }
 
@@ -191,7 +192,7 @@ class ItemSAO : public ServerActiveObject
        }
 
        ItemSAO(ServerEnvironment *env, v3f pos,
-                       const std::string itemstring):
+                       const std::string &itemstring):
                ServerActiveObject(env, pos),
                m_itemstring(itemstring),
                m_itemstring_changed(false),
@@ -211,7 +212,7 @@ class ItemSAO : public ServerActiveObject
                if(m_move_interval.step(dtime, interval)==false)
                        return;
                dtime = interval;
-               
+
                core::aabbox3d<f32> box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.);
                collisionMoveResult moveresult;
                // Apply gravity
@@ -222,13 +223,12 @@ class ItemSAO : public ServerActiveObject
                if(m_speed_f.getLength()*dtime > pos_max_d)
                        m_speed_f *= pos_max_d / (m_speed_f.getLength()*dtime);
                v3f pos_f = getBasePosition();
-               v3f pos_f_old = pos_f;
                v3f accel_f = v3f(0,0,0);
                f32 stepheight = 0;
                moveresult = collisionMoveSimple(m_env,m_env->getGameDef(),
                                pos_max_d, box, stepheight, dtime,
                                pos_f, m_speed_f, accel_f);
-               
+
                if(send_recommended == false)
                        return;
 
@@ -326,7 +326,7 @@ class ItemSAO : public ServerActiveObject
                                m_itemstring_changed = true;
                        }
                }
-               
+
                return 0;
        }
 
@@ -350,7 +350,7 @@ class ItemSAO : public ServerActiveObject
 ItemSAO proto_ItemSAO(NULL, v3f(0,0,0), "");
 
 ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
-               const std::string itemstring)
+                                  const std::string &itemstring)
 {
        return new ItemSAO(env, pos, itemstring);
 }
@@ -391,7 +391,7 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
                ServerActiveObject::registerType(getType(), create);
                return;
        }
-       
+
        // Initialize something to armor groups
        m_armor_groups["fleshy"] = 100;
 }
@@ -406,11 +406,11 @@ LuaEntitySAO::~LuaEntitySAO()
 void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
 {
        ServerActiveObject::addedToEnvironment(dtime_s);
-       
+
        // Create entity from name
        m_registered = m_env->getScriptIface()->
                luaentity_Add(m_id, m_init_name.c_str());
-       
+
        if(m_registered){
                // Get properties
                m_env->getScriptIface()->
@@ -527,8 +527,9 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
                        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_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;
                }
        }
 
@@ -669,10 +670,10 @@ int LuaEntitySAO::punch(v3f dir,
                return 0;
        }
 
-       // It's best that attachments cannot be punched 
+       // It's best that attachments cannot be punched
        if(isAttached())
                return 0;
-       
+
        ItemStack *punchitem = NULL;
        ItemStack punchitem_static;
        if(puncher){
@@ -685,11 +686,11 @@ int LuaEntitySAO::punch(v3f dir,
                        toolcap,
                        punchitem,
                        time_from_last_punch);
-       
+
        if(result.did_punch)
        {
                setHP(getHP() - result.damage);
-               
+
 
                std::string punchername = "nil";
 
@@ -699,7 +700,7 @@ int LuaEntitySAO::punch(v3f dir,
                actionstream<<getDescription()<<" punched by "
                                <<punchername<<", damage "<<result.damage
                                <<" hp, health now "<<getHP()<<" hp"<<std::endl;
-               
+
                {
                        std::string str = gob_cmd_punched(result.damage, getHP());
                        // create message and add to list
@@ -885,7 +886,7 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
        // If the object is attached client-side, don't waste bandwidth sending its position to clients
        if(isAttached())
                return;
-       
+
        m_last_sent_move_precision = m_base_position.getDistanceFrom(
                        m_last_sent_position);
        m_last_sent_position_timer = 0;
@@ -942,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),
@@ -967,6 +969,8 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
        m_physics_override_speed(1),
        m_physics_override_jump(1),
        m_physics_override_gravity(1),
+       m_physics_override_sneak(true),
+       m_physics_override_sneak_glitch(true),
        m_physics_override_sent(false)
 {
        assert(m_player);
@@ -1023,6 +1027,8 @@ void PlayerSAO::removingFromEnvironment()
        {
                m_player->setPlayerSAO(NULL);
                m_player->peer_id = 0;
+               m_env->savePlayer(m_player->getName());
+               m_env->removePlayer(m_player->getName());
        }
 }
 
@@ -1031,11 +1037,6 @@ bool PlayerSAO::isStaticAllowed() const
        return false;
 }
 
-bool PlayerSAO::unlimitedTransferDistance() const
-{
-       return g_settings->getBool("unlimited_player_transfer_distance");
-}
-
 std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
 {
        std::ostringstream os(std::ios::binary);
@@ -1058,7 +1059,9 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
                        os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
                }
                os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
-               os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed, m_physics_override_jump, m_physics_override_gravity)); // 5
+               os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
+                               m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
+                               m_physics_override_sneak_glitch)); // 5
        }
        else
        {
@@ -1185,7 +1188,9 @@ void PlayerSAO::step(float dtime, bool send_recommended)
 
        if(m_physics_override_sent == false){
                m_physics_override_sent = true;
-               std::string str = gob_cmd_update_physics_override(m_physics_override_speed, m_physics_override_jump, m_physics_override_gravity);
+               std::string str = gob_cmd_update_physics_override(m_physics_override_speed,
+                               m_physics_override_jump, m_physics_override_gravity,
+                               m_physics_override_sneak, m_physics_override_sneak_glitch);
                // create message and add to list
                ActiveObjectMessage aom(getId(), true, str);
                m_messages_out.push_back(aom);
@@ -1266,7 +1271,7 @@ int PlayerSAO::punch(v3f dir,
        ServerActiveObject *puncher,
        float time_from_last_punch)
 {
-       // It's best that attachments cannot be punched 
+       // It's best that attachments cannot be punched
        if(isAttached())
                return 0;
 
@@ -1298,14 +1303,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;
 }
 
@@ -1318,6 +1315,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;
@@ -1335,19 +1339,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
@@ -1487,15 +1487,12 @@ bool PlayerSAO::checkMovementCheat()
                */
 
                float player_max_speed = 0;
-               float player_max_speed_up = 0;
                if(m_privs.count("fast") != 0){
                        // Fast speed
                        player_max_speed = m_player->movement_speed_fast;
-                       player_max_speed_up = m_player->movement_speed_fast;
                } else {
                        // Normal speed
                        player_max_speed = m_player->movement_speed_walk;
-                       player_max_speed_up = m_player->movement_speed_walk;
                }
                // Tolerance. With the lag pool we shouldn't need it.
                //player_max_speed *= 2.5;