]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/localplayer.cpp
Replace constant red hurt screen with fade out red
[dragonfireclient.git] / src / localplayer.cpp
index ecfa4467c8f12bc1d7d4539c0782c726e000049c..751478213e13f0eb59f6d82440d1f6efc45bf5ac 100644 (file)
@@ -34,6 +34,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 LocalPlayer::LocalPlayer(IGameDef *gamedef):
        Player(gamedef),
+       isAttached(false),
+       overridePosition(v3f(0,0,0)),
+       last_position(v3f(0,0,0)),
+       last_speed(v3f(0,0,0)),
+       last_pitch(0),
+       last_yaw(0),
+       last_keyPressed(0),
        m_sneak_node(32767,32767,32767),
        m_sneak_node_exists(false),
        m_old_node_below(32767,32767,32767),
@@ -53,6 +60,12 @@ LocalPlayer::~LocalPlayer()
 void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                core::list<CollisionInfo> *collision_info)
 {
+       INodeDefManager *nodemgr = m_gamedef->ndef();
+
+       v3f position = getPosition();
+
+       v3f old_speed = m_speed;
+
        // Copy parent position if local player is attached
        if(isAttached)
        {
@@ -60,15 +73,11 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                return;
        }
 
-       INodeDefManager *nodemgr = m_gamedef->ndef();
-
-       v3f position = getPosition();
-
-       v3f old_speed = m_speed;
-
-       // Skip collision detection if a special movement mode is used
+       // Skip collision detection if noclip mode is used
        bool fly_allowed = m_gamedef->checkLocalPrivilege("fly");
-       bool free_move = fly_allowed && g_settings->getBool("free_move");
+       bool noclip = m_gamedef->checkLocalPrivilege("noclip") &&
+               g_settings->getBool("noclip");
+       bool free_move = noclip && fly_allowed && g_settings->getBool("free_move");
        if(free_move)
        {
         position += m_speed * dtime;
@@ -150,7 +159,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                If sneaking, keep in range from the last walked node and don't
                fall off from it
        */
-       if(control.sneak && m_sneak_node_exists)
+       if(control.sneak && m_sneak_node_exists && !g_settings->getBool("free_move"))
        {
                f32 maxd = 0.5*BS + sneak_max;
                v3f lwn_f = intToFloat(m_sneak_node, BS);
@@ -293,7 +302,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                Report collisions
        */
        bool bouncy_jump = false;
-       if(collision_info)
+       // Dont report if flying
+       if(collision_info && !(g_settings->getBool("free_move") && fly_allowed))
        {
                for(size_t i=0; i<result.collisions.size(); i++){
                        const CollisionInfo &info = result.collisions[i];
@@ -321,7 +331,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                v3s16 camera_np = floatToInt(getEyePosition(), BS);
                MapNode n = map.getNodeNoEx(camera_np);
                if(n.getContent() != CONTENT_IGNORE){
-                       if(nodemgr->get(n).walkable){
+                       if(nodemgr->get(n).walkable && nodemgr->get(n).solidness == 2){
                                camera_barely_in_ceiling = true;
                        }
                }
@@ -359,7 +369,14 @@ void LocalPlayer::applyControl(float dtime)
        
        setPitch(control.pitch);
        setYaw(control.yaw);
-       
+
+       // Nullify speed and don't run positioning code if the player is attached
+       if(isAttached)
+       {
+               setSpeed(v3f(0,0,0));
+               return;
+       }
+
        v3f move_direction = v3f(0,0,1);
        move_direction.rotateXZBy(getYaw());
        
@@ -382,13 +399,13 @@ void LocalPlayer::applyControl(float dtime)
        // Whether superspeed mode is used or not
        bool superspeed = false;
        
-       // If free movement and fast movement, always move fast
-       if(free_move && fast_move)
-               superspeed = true;
-       
        // Old descend control
        if(g_settings->getBool("aux1_descends"))
        {
+               // If free movement and fast movement, always move fast
+               if(free_move && fast_move)
+                       superspeed = true;
+               
                // Auxiliary button 1 (E)
                if(control.aux1)
                {
@@ -423,10 +440,9 @@ void LocalPlayer::applyControl(float dtime)
                // Auxiliary button 1 (E)
                if(control.aux1)
                {
-                       if(!free_move && !is_climbing)
+                       if(!is_climbing)
                        {
-                               // If not free movement but fast is allowed, aux1 is
-                               // "Turbo button"
+                               // aux1 is "Turbo button"
                                if(fast_move)
                                        superspeed = true;
                        }
@@ -438,7 +454,7 @@ void LocalPlayer::applyControl(float dtime)
                        {
                                // In free movement mode, sneak descends
                                v3f speed = getSpeed();
-                               if(fast_move)
+                               if(fast_move && control.aux1)
                                        speed.Y = -20*BS;
                                else
                                        speed.Y = -walkspeed_max;
@@ -480,10 +496,20 @@ void LocalPlayer::applyControl(float dtime)
                if(free_move)
                {
                        v3f speed = getSpeed();
-                       if(fast_move)
-                               speed.Y = 20*BS;
-                       else
-                               speed.Y = walkspeed_max;
+                       
+                       if(g_settings->getBool("aux1_descends"))
+                       {
+                               if(fast_move)
+                                       speed.Y = 20*BS;
+                               else
+                                       speed.Y = walkspeed_max;
+                       } else {
+                               if(fast_move && control.aux1)
+                                       speed.Y = 20*BS;
+                               else
+                                       speed.Y = walkspeed_max;
+                       }
+                       
                        setSpeed(speed);
                }
                else if(m_can_jump)
@@ -523,7 +549,7 @@ void LocalPlayer::applyControl(float dtime)
        // The speed of the player (Y is ignored)
        if(superspeed)
                speed = speed.normalize() * walkspeed_max * 5.0;
-       else if(control.sneak)
+       else if(control.sneak && !free_move)
                speed = speed.normalize() * walkspeed_max / 3.0;
        else
                speed = speed.normalize() * walkspeed_max;
@@ -531,7 +557,7 @@ void LocalPlayer::applyControl(float dtime)
        f32 inc = walk_acceleration * BS * dtime;
        
        // Faster acceleration if fast and free movement
-       if(free_move && fast_move)
+       if(free_move && fast_move && superspeed)
                inc = walk_acceleration * BS * dtime * 10;
        
        // Accelerate to target speed with maximum increment