]> 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 279efafe936265a7021ed1d224f068c9dff1fd2d..c4d9b98457d6c10574b5e7aec07e964c2db52d60 100644 (file)
@@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "map.h"
 #include "client.h"
 #include "content_cao.h"
+#include "util/pointedthing.h"
+#include "client/game.h"
 
 /*
        LocalPlayer
@@ -87,7 +89,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
                new_sneak_node_exists = false;
        } else {
                node = map->getNode(current_node, &is_valid_position);
-               if (!is_valid_position || !nodemgr->get(node).walkable)
+               if (!is_valid_position || nodemgr->get(node).walkable)
                        new_sneak_node_exists = false;
        }
 
@@ -113,7 +115,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
 
                // The node to be sneaked on has to be walkable
                node = map->getNode(p, &is_valid_position);
-               if (!is_valid_position || !nodemgr->get(node).walkable)
+               if (!is_valid_position || ! nodemgr->get(node).walkable)
                        continue;
                // And the node(s) above have to be nonwalkable
                bool ok = true;
@@ -130,7 +132,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
                } else {
                        // legacy behaviour: check just one node
                        node = map->getNode(p + v3s16(0, 1, 0), &is_valid_position);
-                       ok = is_valid_position && !nodemgr->get(node).walkable;
+                       ok = is_valid_position && ! nodemgr->get(node).walkable;
                }
                if (!ok)
                        continue;
@@ -159,7 +161,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
                        node = map->getNode(m_sneak_node + v3s16(0, 3, 0),
                                &is_valid_position);
                        m_sneak_ladder_detected = is_valid_position &&
-                               !nodemgr->get(node).walkable;
+                               ! nodemgr->get(node).walkable;
                }
        }
        return true;
@@ -168,6 +170,9 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
 void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
                std::vector<CollisionInfo> *collision_info)
 {
+       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);
@@ -193,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;
@@ -276,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
@@ -298,7 +322,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
 
        collisionMoveResult result = collisionMoveSimple(env, m_client,
                pos_max_d, m_collisionbox, player_stepheight, dtime,
-               &position, &m_speed, accel_f);
+               &position, &m_speed, accel_f, NULL, true, true);
 
        bool could_sneak = control.sneak && !free_move && !in_liquid &&
                !is_climbing && physics_override_sneak;
@@ -337,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
@@ -495,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;
@@ -590,14 +614,14 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
                                else
                                        speedV.Y = movement_speed_walk;
                        }
-               } else if (m_can_jump) {
+               } else if (m_can_jump || g_settings->getBool("jetpack")) {
                        /*
                                NOTE: The d value in move() affects jump height by
                                raising the height at which the jump speed is kept
                                at its starting value
                        */
                        v3f speedJ = getSpeed();
-                       if (speedJ.Y >= -0.5f * BS) {
+                       if (speedJ.Y >= -0.5f * BS || g_settings->getBool("jetpack")) {
                                speedJ.Y = movement_speed_jump * physics_override_jump;
                                setSpeed(speedJ);
                                m_client->getEventManager()->put(new SimpleTriggerEvent(MtEvent::PLAYER_JUMP));
@@ -620,7 +644,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
        if (superspeed || (is_climbing && fast_climb) ||
                        ((in_liquid || in_liquid_stable) && fast_climb))
                speedH = speedH.normalize() * movement_speed_fast;
-       else if (control.sneak && !free_move && !in_liquid && !in_liquid_stable)
+       else if (control.sneak && !free_move && !in_liquid && !in_liquid_stable && !g_settings->getBool("no_slow"))
                speedH = speedH.normalize() * movement_speed_crouch;
        else
                speedH = speedH.normalize() * movement_speed_walk;
@@ -694,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;
@@ -702,7 +736,7 @@ v3f LocalPlayer::getEyeOffset() const
 
 ClientActiveObject *LocalPlayer::getParent() const
 {
-       return m_cao ? m_cao->getParent() : nullptr;
+       return (m_cao && ! g_settings->getBool("entity_speed")) ? m_cao->getParent() : nullptr;
 }
 
 bool LocalPlayer::isDead() const
@@ -711,6 +745,18 @@ bool LocalPlayer::isDead() const
        return !getCAO()->isImmortal() && hp == 0;
 }
 
+void LocalPlayer::tryReattach(int id)
+{
+       PointedThing pointed(id, v3f(0, 0, 0), v3s16(0, 0, 0), 0);
+       m_client->interact(INTERACT_PLACE, pointed);
+       m_cao->m_waiting_for_reattach = 10;
+}
+
+bool LocalPlayer::isWaitingForReattach() const
+{
+       return g_settings->getBool("entity_speed") && m_cao && ! m_cao->getParent() && m_cao->m_waiting_for_reattach > 0;
+}
+
 // 3D acceleration
 void LocalPlayer::accelerate(const v3f &target_speed, const f32 max_increase_H,
        const f32 max_increase_V, const bool use_pitch)
@@ -773,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);
@@ -896,7 +942,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
 
        collisionMoveResult result = collisionMoveSimple(env, m_client,
                pos_max_d, m_collisionbox, player_stepheight, dtime,
-               &position, &m_speed, accel_f);
+               &position, &m_speed, accel_f, NULL, true, true);
 
        // Positition was slightly changed; update standing node pos
        if (touching_ground)
@@ -1075,7 +1121,7 @@ float LocalPlayer::getSlipFactor(Environment *env, const v3f &speedH)
        Map *map = &env->getMap();
        const ContentFeatures &f = nodemgr->get(map->getNode(getStandingNodePos()));
        int slippery = 0;
-       if (f.walkable)
+       if (f.walkable && ! g_settings->getBool("antislip"))
                slippery = itemgroup_get(f.groups, "slippery");
 
        if (slippery >= 1) {
@@ -1144,7 +1190,7 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env,
 
        // try at peak of jump, zero step height
        collisionMoveResult jump_result = collisionMoveSimple(env, m_client, pos_max_d,
-               m_collisionbox, 0.0f, dtime, &jump_pos, &jump_speed, v3f(0.0f));
+               m_collisionbox, 0.0f, dtime, &jump_pos, &jump_speed, v3f(0.0f), NULL, true, true);
 
        // see if we can get a little bit farther horizontally if we had
        // jumped
@@ -1157,3 +1203,4 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env,
                m_autojump_time = 0.1f;
        }
 }
+