]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_sao.cpp
Fix getCraftRecipe returing wrong reciep due to way to unspecific output matching
[dragonfireclient.git] / src / content_sao.cpp
index 85ab8d307abe4bb4e36682eea48f92ffe6a6c8bc..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()->
@@ -670,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){
@@ -686,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";
 
@@ -700,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
@@ -886,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;
@@ -969,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);
@@ -1025,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());
        }
 }
 
@@ -1033,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);
@@ -1060,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
        {
@@ -1187,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);
@@ -1268,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;
 
@@ -1484,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;