*/
#define MAX_OBJECTDATA_SIZE 450
+//#define WATER_LEVEL (-5)
+#define WATER_LEVEL (0)
+
#endif
{
Player *player = *i;
- // Apply gravity to local player
+ // Apply physics to local player
if(player->isLocal())
{
+ // Apply gravity to local player
v3f speed = player->getSpeed();
speed.Y -= 9.81 * BS * dtime_part * 2;
+
+ /*
+ Apply water resistance
+ */
+ if(player->in_water)
+ {
+ f32 max_down = 1.0*BS;
+ if(speed.Y < -max_down) speed.Y = -max_down;
+
+ f32 max = 2.0*BS;
+ if(speed.getLength() > max)
+ {
+ speed = speed / speed.getLength() * max;
+ }
+ }
+
player->setSpeed(speed);
}
\r
TODO: Remove LazyMeshUpdater. It is not used as supposed.\r
\r
+FIXME: Rats somehow go underground sometimes (you can see it in water)\r
+ - Does their position get saved to a border value or something?\r
+\r
+TODO: MovingObject::move and Player::move are basically the same.\r
+ combine them.\r
+\r
Doing now:\r
======================================================================\r
\r
*/\r
\r
std::cout<<std::endl<<std::endl;\r
+ \r
+ std::cout\r
+ <<" .__ __ __ "<<std::endl\r
+ <<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl\r
+ <<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl\r
+ <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl\r
+ <<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl\r
+ <<" \\/ \\/ \\/ \\/ \\/ "<<std::endl\r
+ <<std::endl\r
+ <<"Now with more waterish water!"\r
+ <<std::endl;\r
+\r
+ std::cout<<std::endl;\r
char templine[100];\r
\r
// Dedicated?\r
for(s16 x = xstart; x <= xend; x++)\r
{\r
try{\r
- if(client.getNode(v3s16(x,y,z)).d == MATERIAL_AIR){\r
+ if(material_pointable(client.getNode(v3s16(x,y,z)).d) == false)\r
continue;\r
- }\r
}catch(InvalidPositionException &e){\r
continue;\r
}\r
bool node_under_sunlight = true;
v3s16 toppos = p + v3s16(0,1,0);
+
+ // Node will be replaced with this
+ u8 replace_material = MATERIAL_AIR;
+ {
+ /*
+ Find out with what material the node will be replaced.
+ It will be replaced with the mostly seen buildable_to.
+ */
+
+ v3s16 dirs[6] = {
+ v3s16(0,0,1), // back
+ v3s16(0,1,0), // top
+ v3s16(1,0,0), // right
+ v3s16(0,0,-1), // front
+ v3s16(0,-1,0), // bottom
+ v3s16(-1,0,0), // left
+ };
+
+ core::map<u8, u16> neighbor_rankings;
+
+ for(u32 i=0; i<sizeof(dirs)/sizeof(dirs[0]); i++)
+ {
+ try{
+ MapNode n2 = getNode(p + dirs[i]);
+
+ if(material_buildable_to(n2.d))
+ {
+ if(neighbor_rankings.find(n2.d) == NULL)
+ neighbor_rankings[n2.d] = 1;
+ else
+ neighbor_rankings[n2.d]
+ = neighbor_rankings[n2.d] + 1;
+ }
+ }
+ catch(InvalidPositionException &e)
+ {
+ }
+ }
+
+ u16 highest_ranking = 0;
+
+ for(core::map<u8, u16>::Iterator
+ i = neighbor_rankings.getIterator();
+ i.atEnd() == false; i++)
+ {
+ u8 m = i.getNode()->getKey();
+ u8 c = i.getNode()->getValue();
+ if(
+ c > highest_ranking ||
+ // Prefer something else than air
+ (c >= highest_ranking && m != MATERIAL_AIR)
+
+ )
+ {
+ replace_material = m;
+ highest_ranking = c;
+ }
+ }
+ }
+
/*
If there is a node at top and it doesn't have sunlight,
there will be no sunlight going down.
Remove the node
*/
MapNode n;
- n.d = MATERIAL_AIR;
+ n.d = replace_material;
n.setLight(0);
setNode(p, n);
for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++)
{
try{
- if(m_block->getNodeParent(v3s16(x,y,z)).d == MATERIAL_AIR){
+ if(material_walkable(m_block->getNodeParent(v3s16(x,y,z)).d)
+ == false)
continue;
- }
}
catch(InvalidPositionException &e)
{
return 2;
}
+// Objects collide with walkable materials
+inline bool material_walkable(u8 m)
+{
+ return (m != MATERIAL_AIR && m != MATERIAL_WATER);
+}
+
+// A liquid resists fast movement
+inline bool material_liquid(u8 m)
+{
+ return (m == MATERIAL_WATER);
+}
+
+// Pointable materials can be pointed to in the map
+inline bool material_pointable(u8 m)
+{
+ return (m != MATERIAL_AIR && m != MATERIAL_WATER);
+}
+
+inline bool material_diggable(u8 m)
+{
+ return (m != MATERIAL_AIR && m != MATERIAL_WATER);
+}
+
+inline bool material_buildable_to(u8 m)
+{
+ return (m == MATERIAL_AIR || m == MATERIAL_WATER);
+}
+
/*
Nodes make a face if materials differ and solidness differs.
Return value:
This is an Y-wise stack of MapBlocks.
*/
-#define WATER_LEVEL (-5)
-
#define SECTOR_OBJECT_TEST 0
#define SECTOR_OBJECT_TREE_1 1
#define SECTOR_OBJECT_BUSH_1 2
Player::Player():
touching_ground(false),
+ in_water(false),
inventory(PLAYER_INVENTORY_SIZE),
peer_id(PEER_ID_NEW),
m_speed(0,0,0),
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 = material_liquid(map.getNode(pp).d);
+ }
+ else
+ {
+ v3s16 pp = floatToInt(position + v3f(0,BS/2,0));
+ in_water = material_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;
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(material_walkable(map.getNode(v3s16(x,y,z)).d) == false){
continue;
}
}
}
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)
virtual bool isLocal() const = 0;
bool touching_ground;
+ bool in_water;
Inventory inventory;
{
// Get material at position
material = m_env.getMap().getNode(p_under).d;
- // If it's air, do nothing
- if(material == MATERIAL_AIR)
+ // If it's not diggable, do nothing
+ if(material_diggable(material) == false)
{
return;
}
n.d = mitem->getMaterial();
try{
- // Don't add a node if there isn't air
+ // Don't add a node if this is not a free space
MapNode n2 = m_env.getMap().getNode(p_over);
- if(n2.d != MATERIAL_AIR)
+ if(material_buildable_to(n2.d) == false)
return;
}
catch(InvalidPositionException &e)