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