better water
parent
4a8973aeac
commit
38353751c9
BIN
data/water.png
BIN
data/water.png
Binary file not shown.
Before Width: | Height: | Size: 103 B After Width: | Height: | Size: 214 B |
|
@ -85,5 +85,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
#define MAX_OBJECTDATA_SIZE 450
|
||||
|
||||
//#define WATER_LEVEL (-5)
|
||||
#define WATER_LEVEL (0)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -101,11 +101,28 @@ void Environment::step(float dtime)
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
22
src/main.cpp
22
src/main.cpp
|
@ -167,6 +167,12 @@ TODO: Check what goes wrong with caching map to disk (Kray)
|
|||
|
||||
TODO: Remove LazyMeshUpdater. It is not used as supposed.
|
||||
|
||||
FIXME: Rats somehow go underground sometimes (you can see it in water)
|
||||
- Does their position get saved to a border value or something?
|
||||
|
||||
TODO: MovingObject::move and Player::move are basically the same.
|
||||
combine them.
|
||||
|
||||
Doing now:
|
||||
======================================================================
|
||||
|
||||
|
@ -1013,6 +1019,19 @@ int main(int argc, char *argv[])
|
|||
*/
|
||||
|
||||
std::cout<<std::endl<<std::endl;
|
||||
|
||||
std::cout
|
||||
<<" .__ __ __ "<<std::endl
|
||||
<<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl
|
||||
<<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl
|
||||
<<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl
|
||||
<<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl
|
||||
<<" \\/ \\/ \\/ \\/ \\/ "<<std::endl
|
||||
<<std::endl
|
||||
<<"Now with more waterish water!"
|
||||
<<std::endl;
|
||||
|
||||
std::cout<<std::endl;
|
||||
char templine[100];
|
||||
|
||||
// Dedicated?
|
||||
|
@ -1830,9 +1849,8 @@ int main(int argc, char *argv[])
|
|||
for(s16 x = xstart; x <= xend; x++)
|
||||
{
|
||||
try{
|
||||
if(client.getNode(v3s16(x,y,z)).d == MATERIAL_AIR){
|
||||
if(material_pointable(client.getNode(v3s16(x,y,z)).d) == false)
|
||||
continue;
|
||||
}
|
||||
}catch(InvalidPositionException &e){
|
||||
continue;
|
||||
}
|
||||
|
|
62
src/map.cpp
62
src/map.cpp
|
@ -1047,6 +1047,66 @@ void Map::removeNodeAndUpdate(v3s16 p,
|
|||
|
||||
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.
|
||||
|
@ -1073,7 +1133,7 @@ void Map::removeNodeAndUpdate(v3s16 p,
|
|||
Remove the node
|
||||
*/
|
||||
MapNode n;
|
||||
n.d = MATERIAL_AIR;
|
||||
n.d = replace_material;
|
||||
n.setLight(0);
|
||||
setNode(p, n);
|
||||
|
||||
|
|
|
@ -145,10 +145,10 @@ void MovingObject::move(float dtime, v3f acceleration)
|
|||
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)
|
||||
{
|
||||
// Doing nothing here will block the player from
|
||||
|
|
|
@ -133,6 +133,34 @@ inline u8 material_solidness(u8 m)
|
|||
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:
|
||||
|
|
|
@ -34,8 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
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
|
||||
|
|
|
@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
Player::Player():
|
||||
touching_ground(false),
|
||||
in_water(false),
|
||||
inventory(PLAYER_INVENTORY_SIZE),
|
||||
peer_id(PEER_ID_NEW),
|
||||
m_speed(0,0,0),
|
||||
|
@ -64,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 = 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;
|
||||
|
||||
|
@ -100,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(material_walkable(map.getNode(v3s16(x,y,z)).d) == false){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -355,11 +374,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)
|
||||
|
|
|
@ -95,6 +95,7 @@ public:
|
|||
virtual bool isLocal() const = 0;
|
||||
|
||||
bool touching_ground;
|
||||
bool in_water;
|
||||
|
||||
Inventory inventory;
|
||||
|
||||
|
|
|
@ -1419,8 +1419,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
{
|
||||
// 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;
|
||||
}
|
||||
|
@ -1484,9 +1484,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue