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