From b4ca06b9d9781214f27f388b1663e4372d7f0667 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 13 Oct 2012 16:24:50 +0000 Subject: Better split of the fluid simulator functionality; removed the old LavaSimulator and WaterSimulator files. git-svn-id: http://mc-server.googlecode.com/svn/trunk@958 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Simulator/FluidSimulator.cpp | 138 ++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) (limited to 'source/Simulator/FluidSimulator.cpp') diff --git a/source/Simulator/FluidSimulator.cpp b/source/Simulator/FluidSimulator.cpp index d352d5d4d..4c867aa79 100644 --- a/source/Simulator/FluidSimulator.cpp +++ b/source/Simulator/FluidSimulator.cpp @@ -2,6 +2,7 @@ #include "Globals.h" #include "FluidSimulator.h" +#include "../World.h" @@ -17,3 +18,140 @@ cFluidSimulator::cFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE + +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::CanWashAway(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_YELLOW_FLOWER: + case E_BLOCK_RED_ROSE: + case E_BLOCK_RED_MUSHROOM: + case E_BLOCK_BROWN_MUSHROOM: + case E_BLOCK_CACTUS: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool cFluidSimulator::IsSolidBlock(BLOCKTYPE a_BlockType) +{ + return !IsPassableForFluid(a_BlockType); +} + + + + + +// TODO Not working very well yet :s +Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over) +{ + char BlockID = m_World->GetBlock(a_X, a_Y, a_Z); + if (!IsAllowedBlock(BlockID)) // No Fluid -> No Flowing direction :D + { + return NONE; + } + + + /* + Disabled because of causing problems and being useless atm + 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 + if (BlockBelow == E_BLOCK_AIR || IsAllowedBlock(BlockBelow)) + return Y_MINUS; + */ + + NIBBLETYPE LowestPoint = m_World->GetBlockMeta(a_X, a_Y, a_Z); //Current Block Meta so only lower points will be counted + int X = 0, Y = 0, Z = 0; //Lowest Pos will be stored here + + 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 + { + return GetFlowingDirection(a_X, a_Y + 1, a_Z, false); + } + + std::vector< Vector3i * > Points; + + Points.reserve(4); //Already allocate 4 places :D + + //add blocks around the checking pos + 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)); + + for (std::vector::iterator it = Points.begin(); it < Points.end(); it++) + { + Vector3i *Pos = (*it); + char BlockID = m_World->GetBlock(Pos->x, Pos->y, Pos->z); + if(IsAllowedBlock(BlockID)) + { + char Meta = m_World->GetBlockMeta(Pos->x, Pos->y, Pos->z); + + if(Meta > LowestPoint) + { + LowestPoint = Meta; + X = Pos->x; + Y = Pos->y; + Z = Pos->z; + } + }else if(BlockID == E_BLOCK_AIR) + { + LowestPoint = 9; //This always dominates + X = Pos->x; + Y = Pos->y; + Z = Pos->z; + + } + delete Pos; + } + + if (LowestPoint == m_World->GetBlockMeta(a_X, a_Y, a_Z)) + 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; +} + + + + -- cgit v1.2.3