]> git.lizzy.rs Git - minetest.git/blobdiff - src/player.cpp
added dedicated server build without irrlicht
[minetest.git] / src / player.cpp
index 080de606738e00b1d60c96b2ef7b8c7941d82ee8..2c04f1f7637a7b2fe80b7c166f4fa6d471b940c9 100644 (file)
@@ -1,3 +1,22 @@
+/*
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
 /*
 (c) 2010 Perttu Ahola <celeron55@gmail.com>
 */
@@ -9,6 +28,7 @@
 
 Player::Player():
        touching_ground(false),
+       in_water(false),
        inventory(PLAYER_INVENTORY_SIZE),
        peer_id(PEER_ID_NEW),
        m_speed(0,0,0),
@@ -45,6 +65,26 @@ void Player::move(f32 dtime, Map &map)
 
        v3s16 pos_i = floatToInt(position);
        
+       /*
+               Check if player is in water
+       */
+       try{
+               if(in_water)
+               {
+                       v3s16 pp = floatToInt(position + v3f(0,0,0));
+                       in_water = content_liquid(map.getNode(pp).d);
+               }
+               else
+               {
+                       v3s16 pp = floatToInt(position + v3f(0,BS/2,0));
+                       in_water = content_liquid(map.getNode(pp).d);
+               }
+       }
+       catch(InvalidPositionException &e)
+       {
+               in_water = false;
+       }
+
        // The frame length is limited to the player going 0.1*BS per call
        f32 d = (float)BS * 0.15;
 
@@ -81,10 +121,8 @@ void Player::move(f32 dtime, Map &map)
        for(s16 y = oldpos_i.Y - 1; y <= oldpos_i.Y + 2; y++){
                for(s16 z = oldpos_i.Z - 1; z <= oldpos_i.Z + 1; z++){
                        for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++){
-                               //std::cout<<"with ("<<x<<","<<y<<","<<z<<"): ";
                                try{
-                                       if(map.getNode(v3s16(x,y,z)).d == MATERIAL_AIR){
-                                               //std::cout<<"air."<<std::endl;
+                                       if(content_walkable(map.getNode(v3s16(x,y,z)).d) == false){
                                                continue;
                                        }
                                }
@@ -190,6 +228,8 @@ void Player::accelerate(v3f target_speed, f32 max_increase)
        RemotePlayer
 */
 
+#ifndef SERVER
+
 RemotePlayer::RemotePlayer(
                scene::ISceneNode* parent,
                IrrlichtDevice *device,
@@ -198,7 +238,7 @@ RemotePlayer::RemotePlayer(
        m_text(NULL)
 {
        m_box = core::aabbox3d<f32>(-BS/2,0,-BS/2,BS/2,BS*2,BS/2);
-       
+
        if(parent != NULL && device != NULL)
        {
                // ISceneNode stores a member called SceneManager
@@ -282,6 +322,9 @@ void RemotePlayer::updateName(const char *name)
        }
 }
 
+#endif
+
+#ifndef SERVER
 /*
        LocalPlayer
 */
@@ -336,11 +379,18 @@ void LocalPlayer::applyControl(float dtime)
        }
        if(control.jump)
        {
-               if(touching_ground){
+               if(touching_ground)
+               {
                        v3f speed = getSpeed();
                        speed.Y = 6.5*BS;
                        setSpeed(speed);
                }
+               else if(in_water)
+               {
+                       v3f speed = getSpeed();
+                       speed.Y = 2.0*BS;
+                       setSpeed(speed);
+               }
        }
 
        // The speed of the player (Y is ignored)
@@ -354,5 +404,5 @@ void LocalPlayer::applyControl(float dtime)
        // Accelerate to target speed with maximum increment
        accelerate(speed, inc);
 }
-
+#endif