Tune caves
[oweals/minetest.git] / src / player.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "player.h"
21 #include "map.h"
22 #include "connection.h"
23 #include "constants.h"
24 #include "utility.h"
25 #ifndef SERVER
26 #include <ITextSceneNode.h>
27 #endif
28 #include "main.h" // For g_settings
29 #include "settings.h"
30 #include "nodedef.h"
31 #include "collision.h"
32 #include "environment.h"
33 #include "gamedef.h"
34 #include "event.h"
35
36 Player::Player(IGameDef *gamedef):
37         touching_ground(false),
38         in_water(false),
39         in_water_stable(false),
40         is_climbing(false),
41         swimming_up(false),
42         inventory(gamedef->idef()),
43         inventory_backup(NULL),
44         hp(20),
45         peer_id(PEER_ID_INEXISTENT),
46 // protected
47         m_gamedef(gamedef),
48         m_pitch(0),
49         m_yaw(0),
50         m_speed(0,0,0),
51         m_position(0,0,0)
52 {
53         updateName("<not set>");
54         resetInventory();
55 }
56
57 Player::~Player()
58 {
59         delete inventory_backup;
60 }
61
62 void Player::resetInventory()
63 {
64         inventory.clear();
65         inventory.addList("main", PLAYER_INVENTORY_SIZE);
66         inventory.addList("craft", 9);
67         inventory.addList("craftpreview", 1);
68         inventory.addList("craftresult", 1);
69 }
70
71 // Y direction is ignored
72 void Player::accelerate(v3f target_speed, f32 max_increase)
73 {
74         v3f d_wanted = target_speed - m_speed;
75         d_wanted.Y = 0;
76         f32 dl_wanted = d_wanted.getLength();
77         f32 dl = dl_wanted;
78         if(dl > max_increase)
79                 dl = max_increase;
80         
81         v3f d = d_wanted.normalize() * dl;
82
83         m_speed.X += d.X;
84         m_speed.Z += d.Z;
85         //m_speed += d;
86
87 #if 0 // old code
88         if(m_speed.X < target_speed.X - max_increase)
89                 m_speed.X += max_increase;
90         else if(m_speed.X > target_speed.X + max_increase)
91                 m_speed.X -= max_increase;
92         else if(m_speed.X < target_speed.X)
93                 m_speed.X = target_speed.X;
94         else if(m_speed.X > target_speed.X)
95                 m_speed.X = target_speed.X;
96
97         if(m_speed.Z < target_speed.Z - max_increase)
98                 m_speed.Z += max_increase;
99         else if(m_speed.Z > target_speed.Z + max_increase)
100                 m_speed.Z -= max_increase;
101         else if(m_speed.Z < target_speed.Z)
102                 m_speed.Z = target_speed.Z;
103         else if(m_speed.Z > target_speed.Z)
104                 m_speed.Z = target_speed.Z;
105 #endif
106 }
107
108 v3s16 Player::getLightPosition() const
109 {
110         return floatToInt(m_position + v3f(0,BS+BS/2,0), BS);
111 }
112
113 void Player::serialize(std::ostream &os)
114 {
115         // Utilize a Settings object for storing values
116         Settings args;
117         args.setS32("version", 1);
118         args.set("name", m_name);
119         //args.set("password", m_password);
120         args.setFloat("pitch", m_pitch);
121         args.setFloat("yaw", m_yaw);
122         args.setV3F("position", m_position);
123         args.setS32("hp", hp);
124
125         args.writeLines(os);
126
127         os<<"PlayerArgsEnd\n";
128         
129         // If actual inventory is backed up due to creative mode, save it
130         // instead of the dummy creative mode inventory
131         if(inventory_backup)
132                 inventory_backup->serialize(os);
133         else
134                 inventory.serialize(os);
135 }
136
137 void Player::deSerialize(std::istream &is)
138 {
139         Settings args;
140         
141         for(;;)
142         {
143                 if(is.eof())
144                         throw SerializationError
145                                         ("Player::deSerialize(): PlayerArgsEnd not found");
146                 std::string line;
147                 std::getline(is, line);
148                 std::string trimmedline = trim(line);
149                 if(trimmedline == "PlayerArgsEnd")
150                         break;
151                 args.parseConfigLine(line);
152         }
153
154         //args.getS32("version"); // Version field value not used
155         std::string name = args.get("name");
156         updateName(name.c_str());
157         setPitch(args.getFloat("pitch"));
158         setYaw(args.getFloat("yaw"));
159         setPosition(args.getV3F("position"));
160         try{
161                 hp = args.getS32("hp");
162         }catch(SettingNotFoundException &e){
163                 hp = 20;
164         }
165
166         inventory.deSerialize(is);
167
168         if(inventory.getList("craftpreview") == NULL)
169         {
170                 // Convert players without craftpreview
171                 inventory.addList("craftpreview", 1);
172
173                 bool craftresult_is_preview = true;
174                 if(args.exists("craftresult_is_preview"))
175                         craftresult_is_preview = args.getBool("craftresult_is_preview");
176                 if(craftresult_is_preview)
177                 {
178                         // Clear craftresult
179                         inventory.getList("craftresult")->changeItem(0, ItemStack());
180                 }
181         }
182 }
183
184 #ifndef SERVER
185 /*
186         LocalPlayer
187 */
188
189 LocalPlayer::LocalPlayer(IGameDef *gamedef):
190         Player(gamedef),
191         m_sneak_node(32767,32767,32767),
192         m_sneak_node_exists(false)
193 {
194         // Initialize hp to 0, so that no hearts will be shown if server
195         // doesn't support health points
196         hp = 0;
197 }
198
199 LocalPlayer::~LocalPlayer()
200 {
201 }
202
203 void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
204                 core::list<CollisionInfo> *collision_info)
205 {
206         INodeDefManager *nodemgr = m_gamedef->ndef();
207
208         v3f position = getPosition();
209         v3f oldpos = position;
210         v3s16 oldpos_i = floatToInt(oldpos, BS);
211
212         v3f old_speed = m_speed;
213
214         /*std::cout<<"oldpos_i=("<<oldpos_i.X<<","<<oldpos_i.Y<<","
215                         <<oldpos_i.Z<<")"<<std::endl;*/
216
217         /*
218                 Calculate new position
219         */
220         position += m_speed * dtime;
221         
222         // Skip collision detection if a special movement mode is used
223         bool free_move = g_settings->getBool("free_move");
224         if(free_move)
225         {
226                 setPosition(position);
227                 return;
228         }
229
230         /*
231                 Collision detection
232         */
233         
234         // Player position in nodes
235         v3s16 pos_i = floatToInt(position, BS);
236         
237         /*
238                 Check if player is in water (the oscillating value)
239         */
240         try{
241                 // If in water, the threshold of coming out is at higher y
242                 if(in_water)
243                 {
244                         v3s16 pp = floatToInt(position + v3f(0,BS*0.1,0), BS);
245                         in_water = nodemgr->get(map.getNode(pp).getContent()).isLiquid();
246                 }
247                 // If not in water, the threshold of going in is at lower y
248                 else
249                 {
250                         v3s16 pp = floatToInt(position + v3f(0,BS*0.5,0), BS);
251                         in_water = nodemgr->get(map.getNode(pp).getContent()).isLiquid();
252                 }
253         }
254         catch(InvalidPositionException &e)
255         {
256                 in_water = false;
257         }
258
259         /*
260                 Check if player is in water (the stable value)
261         */
262         try{
263                 v3s16 pp = floatToInt(position + v3f(0,0,0), BS);
264                 in_water_stable = nodemgr->get(map.getNode(pp).getContent()).isLiquid();
265         }
266         catch(InvalidPositionException &e)
267         {
268                 in_water_stable = false;
269         }
270
271         /*
272                 Check if player is climbing
273         */
274
275         try {
276                 v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
277                 v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
278                 is_climbing = ((nodemgr->get(map.getNode(pp).getContent()).climbable ||
279                 nodemgr->get(map.getNode(pp2).getContent()).climbable) && !free_move);
280         }
281         catch(InvalidPositionException &e)
282         {
283                 is_climbing = false;
284         }
285
286         /*
287                 Collision uncertainty radius
288                 Make it a bit larger than the maximum distance of movement
289         */
290         //f32 d = pos_max_d * 1.1;
291         // A fairly large value in here makes moving smoother
292         f32 d = 0.15*BS;
293
294         // This should always apply, otherwise there are glitches
295         assert(d > pos_max_d);
296
297         float player_radius = BS*0.30;
298         float player_height = BS*1.55;
299         
300         // Maximum distance over border for sneaking
301         f32 sneak_max = BS*0.4;
302
303         /*
304                 If sneaking, player has larger collision radius to keep from
305                 falling
306         */
307         /*if(control.sneak)
308                 player_radius = sneak_max + d*1.1;*/
309         
310         /*
311                 If sneaking, keep in range from the last walked node and don't
312                 fall off from it
313         */
314         if(control.sneak && m_sneak_node_exists)
315         {
316                 f32 maxd = 0.5*BS + sneak_max;
317                 v3f lwn_f = intToFloat(m_sneak_node, BS);
318                 position.X = rangelim(position.X, lwn_f.X-maxd, lwn_f.X+maxd);
319                 position.Z = rangelim(position.Z, lwn_f.Z-maxd, lwn_f.Z+maxd);
320                 
321                 f32 min_y = lwn_f.Y + 0.5*BS;
322                 if(position.Y < min_y)
323                 {
324                         position.Y = min_y;
325
326                         //v3f old_speed = m_speed;
327
328                         if(m_speed.Y < 0)
329                                 m_speed.Y = 0;
330
331                         /*if(collision_info)
332                         {
333                                 // Report fall collision
334                                 if(old_speed.Y < m_speed.Y - 0.1)
335                                 {
336                                         CollisionInfo info;
337                                         info.t = COLLISION_FALL;
338                                         info.speed = m_speed.Y - old_speed.Y;
339                                         collision_info->push_back(info);
340                                 }
341                         }*/
342                 }
343         }
344
345         /*
346                 Calculate player collision box (new and old)
347         */
348         core::aabbox3d<f32> playerbox(
349                 position.X - player_radius,
350                 position.Y - 0.0,
351                 position.Z - player_radius,
352                 position.X + player_radius,
353                 position.Y + player_height,
354                 position.Z + player_radius
355         );
356         core::aabbox3d<f32> playerbox_old(
357                 oldpos.X - player_radius,
358                 oldpos.Y - 0.0,
359                 oldpos.Z - player_radius,
360                 oldpos.X + player_radius,
361                 oldpos.Y + player_height,
362                 oldpos.Z + player_radius
363         );
364
365         /*
366                 If the player's feet touch the topside of any node, this is
367                 set to true.
368
369                 Player is allowed to jump when this is true.
370         */
371         bool touching_ground_was = touching_ground;
372         touching_ground = false;
373
374         /*std::cout<<"Checking collisions for ("
375                         <<oldpos_i.X<<","<<oldpos_i.Y<<","<<oldpos_i.Z
376                         <<") -> ("
377                         <<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z
378                         <<"):"<<std::endl;*/
379         
380         bool standing_on_unloaded = false;
381         
382         /*
383                 Go through every node around the player
384         */
385         for(s16 y = oldpos_i.Y - 1; y <= oldpos_i.Y + 2; y++)
386         for(s16 z = oldpos_i.Z - 1; z <= oldpos_i.Z + 1; z++)
387         for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++)
388         {
389                 bool is_unloaded = false;
390                 try{
391                         // Player collides into walkable nodes
392                         if(nodemgr->get(map.getNode(v3s16(x,y,z))).walkable == false)
393                                 continue;
394                 }
395                 catch(InvalidPositionException &e)
396                 {
397                         is_unloaded = true;
398                         // Doing nothing here will block the player from
399                         // walking over map borders
400                 }
401
402                 core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
403                 
404                 /*
405                         See if the player is touching ground.
406
407                         Player touches ground if player's minimum Y is near node's
408                         maximum Y and player's X-Z-area overlaps with the node's
409                         X-Z-area.
410
411                         Use 0.15*BS so that it is easier to get on a node.
412                 */
413                 if(
414                                 //fabs(nodebox.MaxEdge.Y-playerbox.MinEdge.Y) < d
415                                 fabs(nodebox.MaxEdge.Y-playerbox.MinEdge.Y) < 0.15*BS
416                                 && nodebox.MaxEdge.X-d > playerbox.MinEdge.X
417                                 && nodebox.MinEdge.X+d < playerbox.MaxEdge.X
418                                 && nodebox.MaxEdge.Z-d > playerbox.MinEdge.Z
419                                 && nodebox.MinEdge.Z+d < playerbox.MaxEdge.Z
420                 ){
421                         touching_ground = true;
422                         if(is_unloaded)
423                                 standing_on_unloaded = true;
424                 }
425                 
426                 // If player doesn't intersect with node, ignore node.
427                 if(playerbox.intersectsWithBox(nodebox) == false)
428                         continue;
429                 
430                 /*
431                         Go through every axis
432                 */
433                 v3f dirs[3] = {
434                         v3f(0,0,1), // back-front
435                         v3f(0,1,0), // top-bottom
436                         v3f(1,0,0), // right-left
437                 };
438                 for(u16 i=0; i<3; i++)
439                 {
440                         /*
441                                 Calculate values along the axis
442                         */
443                         f32 nodemax = nodebox.MaxEdge.dotProduct(dirs[i]);
444                         f32 nodemin = nodebox.MinEdge.dotProduct(dirs[i]);
445                         f32 playermax = playerbox.MaxEdge.dotProduct(dirs[i]);
446                         f32 playermin = playerbox.MinEdge.dotProduct(dirs[i]);
447                         f32 playermax_old = playerbox_old.MaxEdge.dotProduct(dirs[i]);
448                         f32 playermin_old = playerbox_old.MinEdge.dotProduct(dirs[i]);
449                         
450                         /*
451                                 Check collision for the axis.
452                                 Collision happens when player is going through a surface.
453                         */
454                         /*f32 neg_d = d;
455                         f32 pos_d = d;
456                         // Make it easier to get on top of a node
457                         if(i == 1)
458                                 neg_d = 0.15*BS;
459                         bool negative_axis_collides =
460                                 (nodemax > playermin && nodemax <= playermin_old + neg_d
461                                         && m_speed.dotProduct(dirs[i]) < 0);
462                         bool positive_axis_collides =
463                                 (nodemin < playermax && nodemin >= playermax_old - pos_d
464                                         && m_speed.dotProduct(dirs[i]) > 0);*/
465                         bool negative_axis_collides =
466                                 (nodemax > playermin && nodemax <= playermin_old + d
467                                         && m_speed.dotProduct(dirs[i]) < 0);
468                         bool positive_axis_collides =
469                                 (nodemin < playermax && nodemin >= playermax_old - d
470                                         && m_speed.dotProduct(dirs[i]) > 0);
471                         bool main_axis_collides =
472                                         negative_axis_collides || positive_axis_collides;
473                         
474                         /*
475                                 Check overlap of player and node in other axes
476                         */
477                         bool other_axes_overlap = true;
478                         for(u16 j=0; j<3; j++)
479                         {
480                                 if(j == i)
481                                         continue;
482                                 f32 nodemax = nodebox.MaxEdge.dotProduct(dirs[j]);
483                                 f32 nodemin = nodebox.MinEdge.dotProduct(dirs[j]);
484                                 f32 playermax = playerbox.MaxEdge.dotProduct(dirs[j]);
485                                 f32 playermin = playerbox.MinEdge.dotProduct(dirs[j]);
486                                 if(!(nodemax - d > playermin && nodemin + d < playermax))
487                                 {
488                                         other_axes_overlap = false;
489                                         break;
490                                 }
491                         }
492                         
493                         /*
494                                 If this is a collision, revert the position in the main
495                                 direction.
496                         */
497                         if(other_axes_overlap && main_axis_collides)
498                         {
499                                 //v3f old_speed = m_speed;
500
501                                 m_speed -= m_speed.dotProduct(dirs[i]) * dirs[i];
502                                 position -= position.dotProduct(dirs[i]) * dirs[i];
503                                 position += oldpos.dotProduct(dirs[i]) * dirs[i];
504                                 
505                                 /*if(collision_info)
506                                 {
507                                         // Report fall collision
508                                         if(old_speed.Y < m_speed.Y - 0.1)
509                                         {
510                                                 CollisionInfo info;
511                                                 info.t = COLLISION_FALL;
512                                                 info.speed = m_speed.Y - old_speed.Y;
513                                                 collision_info->push_back(info);
514                                         }
515                                 }*/
516                         }
517                 
518                 }
519         } // xyz
520
521         /*
522                 Check the nodes under the player to see from which node the
523                 player is sneaking from, if any.
524         */
525         {
526                 v3s16 pos_i_bottom = floatToInt(position - v3f(0,BS/2,0), BS);
527                 v2f player_p2df(position.X, position.Z);
528                 f32 min_distance_f = 100000.0*BS;
529                 // If already seeking from some node, compare to it.
530                 /*if(m_sneak_node_exists)
531                 {
532                         v3f sneaknode_pf = intToFloat(m_sneak_node, BS);
533                         v2f sneaknode_p2df(sneaknode_pf.X, sneaknode_pf.Z);
534                         f32 d_horiz_f = player_p2df.getDistanceFrom(sneaknode_p2df);
535                         f32 d_vert_f = fabs(sneaknode_pf.Y + BS*0.5 - position.Y);
536                         // Ignore if player is not on the same level (likely dropped)
537                         if(d_vert_f < 0.15*BS)
538                                 min_distance_f = d_horiz_f;
539                 }*/
540                 v3s16 new_sneak_node = m_sneak_node;
541                 for(s16 x=-1; x<=1; x++)
542                 for(s16 z=-1; z<=1; z++)
543                 {
544                         v3s16 p = pos_i_bottom + v3s16(x,0,z);
545                         v3f pf = intToFloat(p, BS);
546                         v2f node_p2df(pf.X, pf.Z);
547                         f32 distance_f = player_p2df.getDistanceFrom(node_p2df);
548                         f32 max_axis_distance_f = MYMAX(
549                                         fabs(player_p2df.X-node_p2df.X),
550                                         fabs(player_p2df.Y-node_p2df.Y));
551                                         
552                         if(distance_f > min_distance_f ||
553                                         max_axis_distance_f > 0.5*BS + sneak_max + 0.1*BS)
554                                 continue;
555
556                         try{
557                                 // The node to be sneaked on has to be walkable
558                                 if(nodemgr->get(map.getNode(p)).walkable == false)
559                                         continue;
560                                 // And the node above it has to be nonwalkable
561                                 if(nodemgr->get(map.getNode(p+v3s16(0,1,0))).walkable == true)
562                                         continue;
563                         }
564                         catch(InvalidPositionException &e)
565                         {
566                                 continue;
567                         }
568
569                         min_distance_f = distance_f;
570                         new_sneak_node = p;
571                 }
572                 
573                 bool sneak_node_found = (min_distance_f < 100000.0*BS*0.9);
574                 
575                 if(control.sneak && m_sneak_node_exists)
576                 {
577                         if(sneak_node_found)
578                                 m_sneak_node = new_sneak_node;
579                 }
580                 else
581                 {
582                         m_sneak_node = new_sneak_node;
583                         m_sneak_node_exists = sneak_node_found;
584                 }
585
586                 /*
587                         If sneaking, the player's collision box can be in air, so
588                         this has to be set explicitly
589                 */
590                 if(sneak_node_found && control.sneak)
591                         touching_ground = true;
592         }
593         
594         /*
595                 Set new position
596         */
597         setPosition(position);
598         
599         /*
600                 Report collisions
601         */
602         if(collision_info)
603         {
604                 // Report fall collision
605                 if(old_speed.Y < m_speed.Y - 0.1 && !standing_on_unloaded)
606                 {
607                         CollisionInfo info;
608                         info.t = COLLISION_FALL;
609                         info.speed = m_speed.Y - old_speed.Y;
610                         collision_info->push_back(info);
611                 }
612         }
613
614         if(!touching_ground_was && touching_ground){
615                 MtEvent *e = new SimpleTriggerEvent("PlayerRegainGround");
616                 m_gamedef->event()->put(e);
617         }
618 }
619
620 void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
621 {
622         move(dtime, map, pos_max_d, NULL);
623 }
624
625 void LocalPlayer::applyControl(float dtime)
626 {
627         // Clear stuff
628         swimming_up = false;
629
630         // Random constants
631         f32 walk_acceleration = 4.0 * BS;
632         f32 walkspeed_max = 4.0 * BS;
633         
634         setPitch(control.pitch);
635         setYaw(control.yaw);
636         
637         v3f move_direction = v3f(0,0,1);
638         move_direction.rotateXZBy(getYaw());
639         
640         v3f speed = v3f(0,0,0);
641
642         bool free_move = g_settings->getBool("free_move");
643         bool fast_move = g_settings->getBool("fast_move");
644         bool continuous_forward = g_settings->getBool("continuous_forward");
645
646         if(free_move || is_climbing)
647         {
648                 v3f speed = getSpeed();
649                 speed.Y = 0;
650                 setSpeed(speed);
651         }
652
653         // Whether superspeed mode is used or not
654         bool superspeed = false;
655         
656         // If free movement and fast movement, always move fast
657         if(free_move && fast_move)
658                 superspeed = true;
659         
660         // Auxiliary button 1 (E)
661         if(control.aux1)
662         {
663                 if(free_move)
664                 {
665                         // In free movement mode, aux1 descends
666                         v3f speed = getSpeed();
667                         if(fast_move)
668                                 speed.Y = -20*BS;
669                         else
670                                 speed.Y = -walkspeed_max;
671                         setSpeed(speed);
672                 }
673                 else if(is_climbing)
674                 {
675                         v3f speed = getSpeed();
676                         speed.Y = -3*BS;
677                         setSpeed(speed);
678                 }
679                 else
680                 {
681                         // If not free movement but fast is allowed, aux1 is
682                         // "Turbo button"
683                         if(fast_move)
684                                 superspeed = true;
685                 }
686         }
687
688         if(continuous_forward)
689                 speed += move_direction;
690
691         if(control.up)
692         {
693                 if(continuous_forward)
694                         superspeed = true;
695                 else
696                         speed += move_direction;
697         }
698         if(control.down)
699         {
700                 speed -= move_direction;
701         }
702         if(control.left)
703         {
704                 speed += move_direction.crossProduct(v3f(0,1,0));
705         }
706         if(control.right)
707         {
708                 speed += move_direction.crossProduct(v3f(0,-1,0));
709         }
710         if(control.jump)
711         {
712                 if(free_move)
713                 {
714                         v3f speed = getSpeed();
715                         if(fast_move)
716                                 speed.Y = 20*BS;
717                         else
718                                 speed.Y = walkspeed_max;
719                         setSpeed(speed);
720                 }
721                 else if(touching_ground)
722                 {
723                         /*
724                                 NOTE: The d value in move() affects jump height by
725                                 raising the height at which the jump speed is kept
726                                 at its starting value
727                         */
728                         v3f speed = getSpeed();
729                         if(speed.Y >= -0.5*BS)
730                         {
731                                 speed.Y = 6.5*BS;
732                                 setSpeed(speed);
733                                 
734                                 MtEvent *e = new SimpleTriggerEvent("PlayerJump");
735                                 m_gamedef->event()->put(e);
736                         }
737                 }
738                 // Use the oscillating value for getting out of water
739                 // (so that the player doesn't fly on the surface)
740                 else if(in_water)
741                 {
742                         v3f speed = getSpeed();
743                         speed.Y = 1.5*BS;
744                         setSpeed(speed);
745                         swimming_up = true;
746                 }
747                 else if(is_climbing)
748                 {
749                         v3f speed = getSpeed();
750                         speed.Y = 3*BS;
751                         setSpeed(speed);
752                 }
753         }
754
755         // The speed of the player (Y is ignored)
756         if(superspeed)
757                 speed = speed.normalize() * walkspeed_max * 5.0;
758         else if(control.sneak)
759                 speed = speed.normalize() * walkspeed_max / 3.0;
760         else
761                 speed = speed.normalize() * walkspeed_max;
762         
763         f32 inc = walk_acceleration * BS * dtime;
764         
765         // Faster acceleration if fast and free movement
766         if(free_move && fast_move)
767                 inc = walk_acceleration * BS * dtime * 10;
768         
769         // Accelerate to target speed with maximum increment
770         accelerate(speed, inc);
771 }
772
773 v3s16 LocalPlayer::getStandingNodePos()
774 {
775         if(m_sneak_node_exists)
776                 return m_sneak_node;
777         return floatToInt(getPosition(), BS);
778 }
779
780 #endif
781