tuned lava/universal damage code
[oweals/minetest.git] / src / game.cpp
index 0f858e879694cc3404a896e207ec0223d91e8afe..c740ed252c2c949ba6abbffd57923dba8b0af215 100644 (file)
@@ -417,7 +417,7 @@ void getPointedNode(Client *client, v3f player_position,
                try
                {
                        n = client->getNode(v3s16(x,y,z));
-                       if(content_pointable(n.d) == false)
+                       if(content_pointable(n.getContent()) == false)
                                continue;
                }
                catch(InvalidPositionException &e)
@@ -442,9 +442,9 @@ void getPointedNode(Client *client, v3f player_position,
                /*
                        Meta-objects
                */
-               if(n.d == CONTENT_TORCH)
+               if(n.getContent() == CONTENT_TORCH)
                {
-                       v3s16 dir = unpackDir(n.dir);
+                       v3s16 dir = unpackDir(n.param2);
                        v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
                        dir_f *= BS/2 - BS/6 - BS/20;
                        v3f cpf = npf + dir_f;
@@ -489,9 +489,9 @@ void getPointedNode(Client *client, v3f player_position,
                                }
                        }
                }
-               else if(n.d == CONTENT_SIGN_WALL)
+               else if(n.getContent() == CONTENT_SIGN_WALL)
                {
-                       v3s16 dir = unpackDir(n.dir);
+                       v3s16 dir = unpackDir(n.param2);
                        v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
                        dir_f *= BS/2 - BS/6 - BS/20;
                        v3f cpf = npf + dir_f;
@@ -538,9 +538,59 @@ void getPointedNode(Client *client, v3f player_position,
                                }
                        }
                }
-               else if(n.d == CONTENT_RAIL)
+
+               else if(n.getContent() == CONTENT_LADDER)
+               {
+                       v3s16 dir = unpackDir(n.param2);
+                       v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
+                       dir_f *= BS/2 - BS/6 - BS/20;
+                       v3f cpf = npf + dir_f;
+                       f32 distance = (cpf - camera_position).getLength();
+
+                       v3f vertices[4] =
+                       {
+                               v3f(BS*0.42,-BS/2,-BS/2),
+                               v3f(BS*0.49, BS/2, BS/2),
+                       };
+
+                       for(s32 i=0; i<2; i++)
+                       {
+                               if(dir == v3s16(1,0,0))
+                                       vertices[i].rotateXZBy(0);
+                               if(dir == v3s16(-1,0,0))
+                                       vertices[i].rotateXZBy(180);
+                               if(dir == v3s16(0,0,1))
+                                       vertices[i].rotateXZBy(90);
+                               if(dir == v3s16(0,0,-1))
+                                       vertices[i].rotateXZBy(-90);
+                               if(dir == v3s16(0,-1,0))
+                                       vertices[i].rotateXYBy(-90);
+                               if(dir == v3s16(0,1,0))
+                                       vertices[i].rotateXYBy(90);
+
+                               vertices[i] += npf;
+                       }
+
+                       core::aabbox3d<f32> box;
+
+                       box = core::aabbox3d<f32>(vertices[0]);
+                       box.addInternalPoint(vertices[1]);
+
+                       if(distance < mindistance)
+                       {
+                               if(box.intersectsWithLine(shootline))
+                               {
+                                       nodefound = true;
+                                       nodepos = np;
+                                       neighbourpos = np;
+                                       mindistance = distance;
+                                       nodehilightbox = box;
+                               }
+                       }
+               }
+               else if(n.getContent() == CONTENT_RAIL)
                {
-                       v3s16 dir = unpackDir(n.dir);
+                       v3s16 dir = unpackDir(n.param0);
                        v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
                        dir_f *= BS/2 - BS/6 - BS/20;
                        v3f cpf = npf + dir_f;
@@ -715,7 +765,8 @@ void the_game(
        std::string password,
        std::string address,
        u16 port,
-       std::wstring &error_message
+       std::wstring &error_message,
+    std::string configpath
 )
 {
        video::IVideoDriver* driver = device->getVideoDriver();
@@ -755,7 +806,7 @@ void the_game(
        if(address == ""){
                draw_load_screen(L"Creating server...", driver, font);
                std::cout<<DTIME<<"Creating server"<<std::endl;
-               server = new Server(map_dir);
+               server = new Server(map_dir, configpath);
                server->start(port);
        }
        
@@ -1011,6 +1062,14 @@ void the_game(
        {
                //std::cerr<<"frame"<<std::endl;
 
+               if(client.accessDenied())
+               {
+                       error_message = L"Access denied. Reason: "
+                                       +client.accessDeniedReason();
+                       std::cout<<DTIME<<wide_to_narrow(error_message)<<std::endl;
+                       break;
+               }
+
                if(g_gamecallback->disconnect_requested)
                {
                        g_gamecallback->disconnect_requested = false;
@@ -1038,9 +1097,9 @@ void the_game(
                //bool screensize_changed = screensize != last_screensize;
 
                // Resize hotbar
-               if(screensize.Y <= 600)
+               if(screensize.Y <= 800)
                        hotbar_imagesize = 32;
-               else if(screensize.Y <= 1024)
+               else if(screensize.Y <= 1280)
                        hotbar_imagesize = 48;
                else
                        hotbar_imagesize = 64;
@@ -1470,7 +1529,8 @@ void the_game(
                }
                
                // Get player position
-               v3f player_position = client.getPlayerPosition();
+               v3f camera_position;
+               v3f player_position = client.getPlayerPosition(&camera_position);
 
                //TimeTaker //timer2("//timer2");
 
@@ -1530,11 +1590,6 @@ void the_game(
                v3f camera_direction = v3f(0,0,1);
                camera_direction.rotateYZBy(camera_pitch);
                camera_direction.rotateXZBy(camera_yaw);
-               
-               // This is at the height of the eyes of the current figure
-               //v3f camera_position = player_position + v3f(0, BS+BS/2, 0);
-               // This is more like in minecraft
-               v3f camera_position = player_position + v3f(0, BS+BS*0.625, 0);
 
                camera->setPosition(camera_position);
                // *100.0 helps in large map coordinates
@@ -1656,6 +1711,8 @@ void the_game(
                        else if(input->getRightClicked())
                        {
                                std::cout<<DTIME<<"Right-clicked object"<<std::endl;
+                               client.clickActiveObject(1,
+                                               selected_active_object->getId(), g_selected_item);
                        }
                }
                else // selected_object == NULL
@@ -1759,7 +1816,7 @@ void the_game(
                                        }
 
                                        // Get digging properties for material and tool
-                                       u8 material = n.d;
+                                       content_t material = n.getContent();
                                        DiggingProperties prop =
                                                        getDiggingProperties(material, toolname);
                                        
@@ -1952,9 +2009,15 @@ void the_game(
                */
                if(farmesh)
                {
+                       farmesh_range = draw_control.wanted_range * 10;
+                       if(draw_control.range_all && farmesh_range < 500)
+                               farmesh_range = 500;
+                       if(farmesh_range > 1000)
+                               farmesh_range = 1000;
+
                        farmesh->step(dtime);
                        farmesh->update(v2f(player_position.X, player_position.Z),
-                                       0.05+brightness*0.95);
+                                       0.05+brightness*0.95, farmesh_range);
                }
                
                // Store brightness value
@@ -2021,7 +2084,7 @@ void the_game(
                        endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
                        
                        char temptext[300];
-                       snprintf(temptext, 300, "Minetest-delta %s ("
+                       snprintf(temptext, 300, "Minetest-c55 %s ("
                                        "R: range_all=%i"
                                        ")"
                                        " drawtime=%.0f, beginscenetime=%.0f"
@@ -2145,6 +2208,7 @@ void the_game(
                if(client.getLocalInventoryUpdated()
                                || g_selected_item != old_selected_item)
                {
+                       client.selectPlayerItem(g_selected_item);
                        old_selected_item = g_selected_item;
                        //std::cout<<"Updating local inventory"<<std::endl;
                        client.getLocalInventory(local_inventory);
@@ -2251,6 +2315,13 @@ void the_game(
                // 0-1ms
                guienv->drawAll();
 
+               /*
+                       Environment post fx
+               */
+               {
+                       client.getEnv()->drawPostFx(driver, camera_position);
+               }
+               
                /*
                        Draw hotbar
                */
@@ -2273,13 +2344,6 @@ void the_game(
                                        NULL);
                }
 
-               /*
-                       Environment post fx
-               */
-               {
-                       client.getEnv()->drawPostFx(driver, camera_position);
-               }
-               
                /*
                        End scene
                */