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