Commented out debug statements again
[oweals/minetest.git] / src / player.cpp
index c43276ef132db71f8dbc1766953ef674ea8cd585..7cfdfebb69d45ebb739f50c43b51b5bd750b9e5a 100644 (file)
@@ -33,6 +33,7 @@ Player::Player():
        craftresult_is_preview(true),
        hp(20),
        peer_id(PEER_ID_INEXISTENT),
+       m_selected_item(0),
        m_pitch(0),
        m_yaw(0),
        m_speed(0,0,0),
@@ -47,6 +48,11 @@ Player::~Player()
        delete inventory_backup;
 }
 
+void Player::wieldItem(u16 item)
+{
+       m_selected_item = item;
+}
+
 void Player::resetInventory()
 {
        inventory.clear();
@@ -324,7 +330,18 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
        /*
                Calculate new position
        */
-       position += m_speed * dtime;
+       if(is_frozen) {
+               // Still move very slowly so as not to feel all completely stuck
+               position += m_speed * dtime * 0.001;
+       }
+       else {
+               position += m_speed * dtime;
+       }
+       
+       /*
+               If the player enters an unloaded chunk this is set to true.
+       */
+       is_frozen = false;
 
        // Skip collision detection if a special movement mode is used
        bool free_move = g_settings.getBool("free_move");
@@ -375,6 +392,21 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                in_water_stable = false;
        }
 
+       /*
+               Check if player is climbing
+       */
+
+       try {
+               v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
+               v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
+               is_climbing = ((content_features(map.getNode(pp).getContent()).climbable ||
+                               content_features(map.getNode(pp2).getContent()).climbable) && !free_move);
+       }
+       catch(InvalidPositionException &e)
+       {
+               is_climbing = false;
+       }
+
        /*
                Collision uncertainty radius
                Make it a bit larger than the maximum distance of movement
@@ -461,7 +493,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                Player is allowed to jump when this is true.
        */
        touching_ground = false;
-       
+
        /*std::cout<<"Checking collisions for ("
                        <<oldpos_i.X<<","<<oldpos_i.Y<<","<<oldpos_i.Z
                        <<") -> ("
@@ -482,8 +514,11 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                }
                catch(InvalidPositionException &e)
                {
-                       // Doing nothing here will block the player from
-                       // walking over map borders
+                       if(!is_frozen) {
+                               // freeze when entering unloaded areas
+                               is_frozen = true;
+                       }
+                       continue;
                }
 
                core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
@@ -723,7 +758,7 @@ void LocalPlayer::applyControl(float dtime)
        bool fast_move = g_settings.getBool("fast_move");
        bool continuous_forward = g_settings.getBool("continuous_forward");
 
-       if(free_move)
+       if(free_move || is_climbing)
        {
                v3f speed = getSpeed();
                speed.Y = 0;
@@ -750,6 +785,12 @@ void LocalPlayer::applyControl(float dtime)
                                speed.Y = -walkspeed_max;
                        setSpeed(speed);
                }
+               else if(is_climbing)
+               {
+                       v3f speed = getSpeed();
+                       speed.Y = -3*BS;
+                       setSpeed(speed);
+               }
                else
                {
                        // If not free movement but fast is allowed, aux1 is
@@ -812,6 +853,12 @@ void LocalPlayer::applyControl(float dtime)
                        setSpeed(speed);
                        swimming_up = true;
                }
+               else if(is_climbing)
+               {
+                       v3f speed = getSpeed();
+                       speed.Y = 3*BS;
+                       setSpeed(speed);
+               }
        }
 
        // The speed of the player (Y is ignored)