]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/localplayer.cpp
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / client / localplayer.cpp
index 7d532c602e8b3a678e098bafb96834fecda8d026..c4d9b98457d6c10574b5e7aec07e964c2db52d60 100644 (file)
@@ -172,7 +172,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
 {
        if (m_cao && m_cao->m_waiting_for_reattach > 0)
                m_cao->m_waiting_for_reattach -= dtime;
-       
+
        // Node at feet position, update each ClientEnvironment::step()
        if (!collision_info || collision_info->empty())
                m_standing_node = floatToInt(m_position, BS);
@@ -198,9 +198,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
        PlayerSettings &player_settings = getPlayerSettings();
 
        // Skip collision detection if noclip mode is used
-       bool fly_allowed = m_client->checkLocalPrivilege("fly");
-       bool noclip = m_client->checkLocalPrivilege("noclip") && player_settings.noclip;
-       bool free_move = player_settings.free_move && fly_allowed;
+       bool fly_allowed = m_client->checkLocalPrivilege("fly") || g_settings->getBool("freecam");
+       bool noclip = (m_client->checkLocalPrivilege("noclip") && player_settings.noclip) || g_settings->getBool("freecam");
+       bool free_move = (player_settings.free_move && fly_allowed) || g_settings->getBool("freecam");
 
        if (noclip && free_move) {
                position += m_speed * dtime;
@@ -232,8 +232,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
                pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS);
                node = map->getNode(pp, &is_valid_position);
                if (is_valid_position) {
-                       in_liquid = nodemgr->get(node.getContent()).isLiquid();
-                       liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
+                       const ContentFeatures &cf = nodemgr->get(node.getContent());
+                       in_liquid = cf.liquid_move_physics;
+                       move_resistance = cf.move_resistance;
                } else {
                        in_liquid = false;
                }
@@ -243,8 +244,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
                pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS);
                node = map->getNode(pp, &is_valid_position);
                if (is_valid_position) {
-                       in_liquid = nodemgr->get(node.getContent()).isLiquid();
-                       liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
+                       const ContentFeatures &cf = nodemgr->get(node.getContent());
+                       in_liquid = cf.liquid_move_physics;
+                       move_resistance = cf.move_resistance;
                } else {
                        in_liquid = false;
                }
@@ -257,7 +259,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
        pp = floatToInt(position + v3f(0.0f), BS);
        node = map->getNode(pp, &is_valid_position);
        if (is_valid_position) {
-               in_liquid_stable = nodemgr->get(node.getContent()).isLiquid();
+               in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics;
        } else {
                in_liquid_stable = false;
        }
@@ -279,6 +281,25 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
                        nodemgr->get(node2.getContent()).climbable) && !free_move;
        }
 
+       if (!is_climbing && !free_move && g_settings->getBool("spider")) {
+               v3s16 spider_positions[4] = {
+                       floatToInt(position + v3f(+1.0f, +0.0f,  0.0f) * BS, BS),
+                       floatToInt(position + v3f(-1.0f, +0.0f,  0.0f) * BS, BS),
+                       floatToInt(position + v3f( 0.0f, +0.0f, +1.0f) * BS, BS),
+                       floatToInt(position + v3f( 0.0f, +0.0f, -1.0f) * BS, BS),
+               };
+
+               for (v3s16 sp : spider_positions) {
+                       bool is_valid;
+                       MapNode node = map->getNode(sp, &is_valid);
+
+                       if (is_valid && nodemgr->get(node.getContent()).walkable) {
+                               is_climbing = true;
+                               break;
+                       }
+               }
+       }
+
        /*
                Collision uncertainty radius
                Make it a bit larger than the maximum distance of movement
@@ -340,7 +361,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
                Player is allowed to jump when this is true.
        */
        bool touching_ground_was = touching_ground;
-       touching_ground = result.touching_ground;
+       touching_ground = result.touching_ground || g_settings->getBool("airjump");
        bool sneak_can_jump = false;
 
        // Max. distance (X, Z) over border for sneaking determined by collision box
@@ -461,8 +482,6 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
                        m_speed.Y += jumpspeed;
                }
                setSpeed(m_speed);
-               if (! m_freecam)
-                       m_legit_speed = m_speed;
                m_can_jump = false;
        }
 
@@ -500,8 +519,8 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
        bool fly_allowed = m_client->checkLocalPrivilege("fly");
        bool fast_allowed = m_client->checkLocalPrivilege("fast");
 
-       bool free_move = fly_allowed && player_settings.free_move;
-       bool fast_move = fast_allowed && player_settings.fast_move;
+       bool free_move = (fly_allowed && player_settings.free_move) || g_settings->getBool("freecam");
+       bool fast_move = (fast_allowed && player_settings.fast_move) || g_settings->getBool("freecam");
        bool pitch_move = (free_move || in_liquid) && player_settings.pitch_move;
        // When aux1_descends is enabled the fast key is used to go down, so fast isn't possible
        bool fast_climb = fast_move && control.aux1 && !player_settings.aux1_descends;
@@ -573,23 +592,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
                }
        }
 
-       if (control.up)
-               speedH += v3f(0.0f, 0.0f, 1.0f);
-
-       if (control.down)
-               speedH -= v3f(0.0f, 0.0f, 1.0f);
-
-       if (!control.up && !control.down)
-               speedH -= v3f(0.0f, 0.0f, 1.0f) * (control.forw_move_joystick_axis / 32767.f);
-
-       if (control.left)
-               speedH += v3f(-1.0f, 0.0f, 0.0f);
-
-       if (control.right)
-               speedH += v3f(1.0f, 0.0f, 0.0f);
-
-       if (!control.left && !control.right)
-               speedH += v3f(1.0f, 0.0f, 0.0f) * (control.sidew_move_joystick_axis / 32767.f);
+       speedH = v3f(sin(control.movement_direction), 0.0f, cos(control.movement_direction));
 
        if (m_autojump) {
                // release autojump after a given time
@@ -646,6 +649,8 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
        else
                speedH = speedH.normalize() * movement_speed_walk;
 
+       speedH *= control.movement_speed; /* Apply analog input */
+
        // Acceleration increase
        f32 incH = 0.0f; // Horizontal (X, Z)
        f32 incV = 0.0f; // Vertical (Y)
@@ -691,19 +696,21 @@ v3s16 LocalPlayer::getStandingNodePos()
 
 v3s16 LocalPlayer::getFootstepNodePos()
 {
+       v3f feet_pos = getPosition() + v3f(0.0f, m_collisionbox.MinEdge.Y, 0.0f);
+
        // Emit swimming sound if the player is in liquid
        if (in_liquid_stable)
-               return floatToInt(getPosition(), BS);
+               return floatToInt(feet_pos, BS);
 
        // BS * 0.05 below the player's feet ensures a 1/16th height
        // nodebox is detected instead of the node below it.
        if (touching_ground)
-               return floatToInt(getPosition() - v3f(0.0f, BS * 0.05f, 0.0f), BS);
+               return floatToInt(feet_pos - v3f(0.0f, BS * 0.05f, 0.0f), BS);
 
        // A larger distance below is necessary for a footstep sound
        // when landing after a jump or fall. BS * 0.5 ensures water
        // sounds when swimming in 1 node deep water.
-       return floatToInt(getPosition() - v3f(0.0f, BS * 0.5f, 0.0f), BS);
+       return floatToInt(feet_pos - v3f(0.0f, BS * 0.5f, 0.0f), BS);
 }
 
 v3s16 LocalPlayer::getLightPosition() const
@@ -711,6 +718,16 @@ v3s16 LocalPlayer::getLightPosition() const
        return floatToInt(m_position + v3f(0.0f, BS * 1.5f, 0.0f), BS);
 }
 
+v3f LocalPlayer::getSendSpeed()
+{
+       v3f speed = getLegitSpeed();
+
+       if (m_client->modsLoaded())
+               speed = m_client->getScript()->get_send_speed(speed);
+
+       return speed;
+}
+
 v3f LocalPlayer::getEyeOffset() const
 {
        float eye_height = camera_barely_in_ceiling ? m_eye_height - 0.125f : m_eye_height;
@@ -802,9 +819,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
        PlayerSettings &player_settings = getPlayerSettings();
 
        // Skip collision detection if noclip mode is used
-       bool fly_allowed = m_client->checkLocalPrivilege("fly");
-       bool noclip = m_client->checkLocalPrivilege("noclip") && player_settings.noclip;
-       bool free_move = noclip && fly_allowed && player_settings.free_move;
+       bool fly_allowed = m_client->checkLocalPrivilege("fly") || g_settings->getBool("freecam");
+       bool noclip = (m_client->checkLocalPrivilege("noclip") && player_settings.noclip) || g_settings->getBool("freecam");
+       bool free_move = (noclip && fly_allowed && player_settings.free_move) || g_settings->getBool("freecam");
        if (free_move) {
                position += m_speed * dtime;
                setPosition(position);
@@ -833,8 +850,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
                pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS);
                node = map->getNode(pp, &is_valid_position);
                if (is_valid_position) {
-                       in_liquid = nodemgr->get(node.getContent()).isLiquid();
-                       liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
+                       const ContentFeatures &cf = nodemgr->get(node.getContent());
+                       in_liquid = cf.liquid_move_physics;
+                       move_resistance = cf.move_resistance;
                } else {
                        in_liquid = false;
                }
@@ -843,8 +861,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
                pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS);
                node = map->getNode(pp, &is_valid_position);
                if (is_valid_position) {
-                       in_liquid = nodemgr->get(node.getContent()).isLiquid();
-                       liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
+                       const ContentFeatures &cf = nodemgr->get(node.getContent());
+                       in_liquid = cf.liquid_move_physics;
+                       move_resistance = cf.move_resistance;
                } else {
                        in_liquid = false;
                }
@@ -856,7 +875,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
        pp = floatToInt(position + v3f(0.0f), BS);
        node = map->getNode(pp, &is_valid_position);
        if (is_valid_position)
-               in_liquid_stable = nodemgr->get(node.getContent()).isLiquid();
+               in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics;
        else
                in_liquid_stable = false;
 
@@ -1125,12 +1144,8 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env,
        if (m_autojump)
                return;
 
-       bool control_forward = control.up ||
-               (!control.up && !control.down &&
-               control.forw_move_joystick_axis < -0.05f);
-
        bool could_autojump =
-               m_can_jump && !control.jump && !control.sneak && control_forward;
+               m_can_jump && !control.jump && !control.sneak && control.isMoving();
 
        if (!could_autojump)
                return;