src/environment.cpp | 8 +++++--- src/localplayer.cpp | 28 +++++++++++++++------------- src/player.cpp | 5 +++-- src/player.h | 6 ++++-- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/environment.cpp b/src/environment.cpp index 610049d..cebb8f3 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -2065,17 +2065,19 @@ void ClientEnvironment::step(float dtime) { // Gravity v3f speed = lplayer->getSpeed(); - if(lplayer->in_water == false) + if(lplayer->in_liquid == false) speed.Y -= lplayer->movement_gravity * dtime_part * 2; // Water floating / sinking - if(lplayer->in_water && !lplayer->swimming_vertical) + if(lplayer->in_liquid && !lplayer->swimming_vertical) speed.Y -= lplayer->movement_liquid_sink * dtime_part * 2; // Water resistance - if(lplayer->in_water_stable || lplayer->in_water) + if(lplayer->in_liquid_stable || lplayer->in_liquid) { v3f d_wanted = -speed / lplayer->movement_liquid_fluidity; + if(lplayer->liquid_viscosity != 0) + d_wanted /= lplayer->liquid_viscosity; f32 dl = d_wanted.getLength(); if(dl > lplayer->movement_liquid_fluidity_smooth) dl = lplayer->movement_liquid_fluidity_smooth; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 4e0bccf..ae83a15 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -94,21 +94,23 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, */ try{ // If in water, the threshold of coming out is at higher y - if(in_water) + if(in_liquid) { v3s16 pp = floatToInt(position + v3f(0,BS*0.1,0), BS); - in_water = nodemgr->get(map.getNode(pp).getContent()).isLiquid(); + in_liquid = nodemgr->get(map.getNode(pp).getContent()).isLiquid(); + liquid_viscosity = nodemgr->get(map.getNode(pp).getContent()).liquid_viscosity; } // If not in water, the threshold of going in is at lower y else { v3s16 pp = floatToInt(position + v3f(0,BS*0.5,0), BS); - in_water = nodemgr->get(map.getNode(pp).getContent()).isLiquid(); + in_liquid = nodemgr->get(map.getNode(pp).getContent()).isLiquid(); + liquid_viscosity = nodemgr->get(map.getNode(pp).getContent()).liquid_viscosity; } } catch(InvalidPositionException &e) { - in_water = false; + in_liquid = false; } /* @@ -116,11 +118,11 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, */ try{ v3s16 pp = floatToInt(position + v3f(0,0,0), BS); - in_water_stable = nodemgr->get(map.getNode(pp).getContent()).isLiquid(); + in_liquid_stable = nodemgr->get(map.getNode(pp).getContent()).isLiquid(); } catch(InvalidPositionException &e) { - in_water_stable = false; + in_liquid_stable = false; } /* @@ -411,7 +413,7 @@ void LocalPlayer::applyControl(float dtime) else speedV.Y = -movement_speed_walk; } - else if(in_water || in_water_stable) + else if(in_liquid || in_liquid_stable) { // Always use fast when aux1_descends & fast_move are enabled in water, since the aux1 button would mean both turbo and "swim down" causing a conflict speedV.Y = -movement_speed_fast; @@ -455,7 +457,7 @@ void LocalPlayer::applyControl(float dtime) else speedV.Y = -movement_speed_walk; } - else if(in_water || in_water_stable) + else if(in_liquid || in_liquid_stable) { if(fast_or_aux1_descends) // Always use fast when aux1_descends & fast_move are enabled in water, since the aux1 button would mean both turbo and "swim down" causing a conflict @@ -533,7 +535,7 @@ void LocalPlayer::applyControl(float dtime) } // Use the oscillating value for getting out of water // (so that the player doesn't fly on the surface) - else if(in_water) + else if(in_liquid) { if(fast_or_aux1_descends) // Always use fast when aux1_descends & fast_move are enabled in water, since the aux1 button would mean both turbo and "swim down" causing a conflict @@ -553,9 +555,9 @@ void LocalPlayer::applyControl(float dtime) } // The speed of the player (Y is ignored) - if(superspeed || (is_climbing && fast_or_aux1_descends) || ((in_water || in_water_stable) && fast_or_aux1_descends)) + if(superspeed || (is_climbing && fast_or_aux1_descends) || ((in_liquid || in_liquid_stable) && fast_or_aux1_descends)) speedH = speedH.normalize() * movement_speed_fast; - else if(control.sneak && !free_move && !in_water && !in_water_stable) + else if(control.sneak && !free_move && !in_liquid && !in_liquid_stable) speedH = speedH.normalize() * movement_speed_crouch; else speedH = speedH.normalize() * movement_speed_walk; @@ -563,7 +565,7 @@ void LocalPlayer::applyControl(float dtime) // Acceleration increase f32 incH = 0; // Horizontal (X, Z) f32 incV = 0; // Vertical (Y) - if((!touching_ground && !free_move && !is_climbing && !in_water && !in_water_stable) || (m_can_jump && control.jump)) + if((!touching_ground && !free_move && !is_climbing && !in_liquid && !in_liquid_stable) || (m_can_jump && control.jump)) { // Jumping and falling if(superspeed || (fast_move && control.aux1)) @@ -574,7 +576,7 @@ void LocalPlayer::applyControl(float dtime) } else if(superspeed || (fast_move && control.aux1)) incH = incV = movement_acceleration_fast * BS * dtime; - else if ((in_water || in_water_stable) && fast_or_aux1_descends) + else if ((in_liquid || in_liquid_stable) && fast_or_aux1_descends) // Always use fast when aux1_descends & fast_move are enabled in water, since the aux1 button would mean both turbo and "swim down" causing a conflict incH = incV = movement_acceleration_fast * BS * dtime; else diff --git a/src/player.cpp b/src/player.cpp index 8361014..9a2df50 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -27,8 +27,9 @@ Player::Player(IGameDef *gamedef): touching_ground(false), - in_water(false), - in_water_stable(false), + in_liquid(false), + in_liquid_stable(false), + liquid_viscosity(0), is_climbing(false), swimming_vertical(false), camera_barely_in_ceiling(false), diff --git a/src/player.h b/src/player.h index 1fa2250..155e9a1 100644 --- a/src/player.h +++ b/src/player.h @@ -196,9 +196,11 @@ class Player bool touching_ground; // This oscillates so that the player jumps a bit above the surface - bool in_water; + bool in_liquid; // This is more stable and defines the maximum speed of the player - bool in_water_stable; + bool in_liquid_stable; + // Gets the viscosity of water to + u8 liquid_viscosity; bool is_climbing; bool swimming_vertical; bool camera_barely_in_ceiling;