2012-10-13 05:53:28 -04:00
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include "FluidSimulator.h"
|
2012-10-13 12:24:50 -04:00
|
|
|
#include "../World.h"
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
cFluidSimulator::cFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid) :
|
2012-10-13 05:53:28 -04:00
|
|
|
super(a_World),
|
|
|
|
m_FluidBlock(a_Fluid),
|
|
|
|
m_StationaryFluidBlock(a_StationaryFluid)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
bool cFluidSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType)
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2012-10-14 13:06:21 -04:00
|
|
|
return ((a_BlockType == m_FluidBlock) || (a_BlockType == m_StationaryFluidBlock));
|
2012-10-13 12:24:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cFluidSimulator::CanWashAway(BLOCKTYPE a_BlockType)
|
|
|
|
{
|
|
|
|
switch (a_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_BROWN_MUSHROOM:
|
|
|
|
case E_BLOCK_CACTUS:
|
2013-04-06 14:20:06 -04:00
|
|
|
case E_BLOCK_COBWEB:
|
2012-10-19 14:48:34 -04:00
|
|
|
case E_BLOCK_CROPS:
|
2012-10-18 15:41:29 -04:00
|
|
|
case E_BLOCK_DEAD_BUSH:
|
2014-03-28 18:51:30 -04:00
|
|
|
case E_BLOCK_LILY_PAD:
|
2012-10-18 15:41:29 -04:00
|
|
|
case E_BLOCK_RAIL:
|
2012-10-16 16:49:17 -04:00
|
|
|
case E_BLOCK_REDSTONE_TORCH_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
2012-10-18 15:41:29 -04:00
|
|
|
case E_BLOCK_REDSTONE_WIRE:
|
|
|
|
case E_BLOCK_RED_MUSHROOM:
|
|
|
|
case E_BLOCK_RED_ROSE:
|
|
|
|
case E_BLOCK_SNOW:
|
2012-10-19 14:48:34 -04:00
|
|
|
case E_BLOCK_SUGARCANE:
|
2012-10-18 15:41:29 -04:00
|
|
|
case E_BLOCK_TALL_GRASS:
|
|
|
|
case E_BLOCK_TORCH:
|
|
|
|
case E_BLOCK_YELLOW_FLOWER:
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cFluidSimulator::IsSolidBlock(BLOCKTYPE a_BlockType)
|
|
|
|
{
|
|
|
|
return !IsPassableForFluid(a_BlockType);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
bool cFluidSimulator::IsPassableForFluid(BLOCKTYPE a_BlockType)
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(a_BlockType == E_BLOCK_AIR) ||
|
|
|
|
(a_BlockType == E_BLOCK_FIRE) ||
|
|
|
|
IsAllowedBlock(a_BlockType) ||
|
|
|
|
CanWashAway(a_BlockType)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cFluidSimulator::IsHigherMeta(NIBBLETYPE a_Meta1, NIBBLETYPE a_Meta2)
|
|
|
|
{
|
|
|
|
if (a_Meta1 == 0)
|
|
|
|
{
|
|
|
|
// Source block is higher than anything, even itself.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((a_Meta1 & 0x08) != 0)
|
|
|
|
{
|
|
|
|
// Falling fluid is higher than anything, including self
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_Meta2 == 0)
|
|
|
|
{
|
|
|
|
// Second block is a source and first block isn't
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((a_Meta2 & 0x08) != 0)
|
|
|
|
{
|
|
|
|
// Second block is falling and the first one is neither a source nor falling
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All special cases have been handled, now it's just a raw comparison:
|
|
|
|
return (a_Meta1 < a_Meta2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-13 12:24:50 -04:00
|
|
|
// TODO Not working very well yet :s
|
|
|
|
Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over)
|
|
|
|
{
|
2013-03-17 09:24:27 -04:00
|
|
|
if ((a_Y < 0) || (a_Y >= cChunkDef::Height))
|
|
|
|
{
|
|
|
|
return NONE;
|
|
|
|
}
|
|
|
|
BLOCKTYPE BlockID = m_World.GetBlock(a_X, a_Y, a_Z);
|
2014-07-17 16:15:34 -04:00
|
|
|
if (!IsAllowedBlock(BlockID)) // No Fluid -> No Flowing direction :D
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
|
|
|
return NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Disabled because of causing problems and being useless atm
|
2014-07-17 16:15:34 -04:00
|
|
|
char BlockBelow = m_World.GetBlock(a_X, a_Y - 1, a_Z); // If there is nothing or fluid below it -> dominating flow is down :D
|
2012-10-13 12:24:50 -04:00
|
|
|
if (BlockBelow == E_BLOCK_AIR || IsAllowedBlock(BlockBelow))
|
|
|
|
return Y_MINUS;
|
|
|
|
*/
|
|
|
|
|
2014-07-17 17:15:53 -04:00
|
|
|
NIBBLETYPE LowestPoint = m_World.GetBlockMeta(a_X, a_Y, a_Z); // Current Block Meta so only lower points will be counted
|
2014-07-17 16:15:34 -04:00
|
|
|
int X = 0, Z = 0; // Lowest Pos will be stored here
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
if (IsAllowedBlock(m_World.GetBlock(a_X, a_Y + 1, a_Z)) && a_Over) // check for upper block to flow because this also affects the flowing direction
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
|
|
|
return GetFlowingDirection(a_X, a_Y + 1, a_Z, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< Vector3i * > Points;
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
Points.reserve(4); // Already allocate 4 places :D
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
// add blocks around the checking pos
|
2012-10-13 12:24:50 -04:00
|
|
|
Points.push_back(new Vector3i(a_X - 1, a_Y, a_Z));
|
|
|
|
Points.push_back(new Vector3i(a_X + 1, a_Y, a_Z));
|
|
|
|
Points.push_back(new Vector3i(a_X, a_Y, a_Z + 1));
|
|
|
|
Points.push_back(new Vector3i(a_X, a_Y, a_Z - 1));
|
|
|
|
|
2014-04-18 15:09:44 -04:00
|
|
|
for (std::vector<Vector3i *>::iterator it = Points.begin(); it < Points.end(); ++it)
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
|
|
|
Vector3i *Pos = (*it);
|
2013-02-28 08:39:20 -05:00
|
|
|
char BlockID = m_World.GetBlock(Pos->x, Pos->y, Pos->z);
|
2014-07-20 17:10:31 -04:00
|
|
|
if (IsAllowedBlock(BlockID))
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
char Meta = m_World.GetBlockMeta(Pos->x, Pos->y, Pos->z);
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2014-07-20 17:10:31 -04:00
|
|
|
if (Meta > LowestPoint)
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
|
|
|
LowestPoint = Meta;
|
|
|
|
X = Pos->x;
|
|
|
|
Z = Pos->z;
|
|
|
|
}
|
2014-06-19 04:49:56 -04:00
|
|
|
}
|
2014-07-20 17:10:31 -04:00
|
|
|
else if (BlockID == E_BLOCK_AIR)
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
LowestPoint = 9; // This always dominates
|
2012-10-13 12:24:50 -04:00
|
|
|
X = Pos->x;
|
|
|
|
Z = Pos->z;
|
|
|
|
|
|
|
|
}
|
|
|
|
delete Pos;
|
2014-06-19 04:49:56 -04:00
|
|
|
Pos = NULL;
|
2012-10-13 12:24:50 -04:00
|
|
|
}
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
if (LowestPoint == m_World.GetBlockMeta(a_X, a_Y, a_Z))
|
2012-10-13 12:24:50 -04:00
|
|
|
return NONE;
|
|
|
|
|
|
|
|
if (a_X - X > 0)
|
|
|
|
{
|
|
|
|
return X_MINUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_X - X < 0)
|
|
|
|
{
|
|
|
|
return X_PLUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_Z - Z > 0)
|
|
|
|
{
|
|
|
|
return Z_MINUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_Z - Z < 0)
|
|
|
|
{
|
|
|
|
return Z_PLUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|