2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
|
#include "FireSimulator.h"
|
2012-10-13 05:53:28 -04:00
|
|
|
|
#include "../World.h"
|
|
|
|
|
#include "../BlockID.h"
|
|
|
|
|
#include "../Defines.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
|
cFireSimulator::cFireSimulator(cWorld & a_World)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
: cSimulator(a_World)
|
|
|
|
|
, m_Blocks(new BlockList)
|
|
|
|
|
, m_Buffer(new BlockList)
|
|
|
|
|
, m_BurningBlocks(new BlockList)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
cFireSimulator::~cFireSimulator()
|
|
|
|
|
{
|
|
|
|
|
delete m_Buffer;
|
|
|
|
|
delete m_Blocks;
|
|
|
|
|
delete m_BurningBlocks;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
|
void cFireSimulator::Simulate(float a_Dt)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
|
|
|
|
m_Buffer->clear();
|
2013-02-28 08:39:20 -05:00
|
|
|
|
std::swap(m_Blocks, m_Buffer);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
|
for (BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
|
|
|
|
Vector3i Pos = *itr;
|
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
|
BLOCKTYPE BlockID = m_World.GetBlock(Pos.x, Pos.y, Pos.z);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
|
if (!IsAllowedBlock(BlockID)) // Check wheather the block is still burning
|
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
|
continue;
|
2013-02-28 08:39:20 -05:00
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
|
if (BurnBlockAround(Pos.x, Pos.y, Pos.z)) //Burn single block and if there was one -> next time again
|
|
|
|
|
{
|
|
|
|
|
m_Blocks->push_back(Pos);
|
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
else
|
2013-02-28 08:39:20 -05:00
|
|
|
|
{
|
|
|
|
|
if (!IsForeverBurnable(m_World.GetBlock(Pos.x, Pos.y - 1, Pos.z)) && !FiresForever(BlockID))
|
|
|
|
|
{
|
|
|
|
|
m_World.SetBlock(Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // for itr - m_Buffer[]
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
|
bool cFireSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2012-10-14 13:06:21 -04:00
|
|
|
|
return (a_BlockType == E_BLOCK_FIRE) || IsBlockLava(a_BlockType);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 02:42:45 -05:00
|
|
|
|
void cFireSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-02-28 02:42:45 -05:00
|
|
|
|
// TODO: This can be optimized
|
2013-02-28 08:39:20 -05:00
|
|
|
|
BLOCKTYPE BlockType = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
2012-10-14 13:06:21 -04:00
|
|
|
|
if (!IsAllowedBlock(BlockType))
|
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
|
return;
|
2012-10-14 13:06:21 -04:00
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
|
// Check for duplicates:
|
|
|
|
|
for (BlockList::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
|
|
|
|
Vector3i Pos = *itr;
|
2012-10-14 13:06:21 -04:00
|
|
|
|
if ((Pos.x == a_BlockX) && (Pos.y == a_BlockY) && (Pos.z == a_BlockZ))
|
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
|
return;
|
2012-10-14 13:06:21 -04:00
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
|
m_Blocks->push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 04:52:11 -04:00
|
|
|
|
bool cFireSimulator::IsForeverBurnable( BLOCKTYPE a_BlockType )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-02-16 06:12:56 -05:00
|
|
|
|
return a_BlockType == E_BLOCK_NETHERRACK;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 04:52:11 -04:00
|
|
|
|
bool cFireSimulator::IsBurnable( BLOCKTYPE a_BlockType )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2012-10-03 04:52:11 -04:00
|
|
|
|
return a_BlockType == E_BLOCK_PLANKS
|
|
|
|
|
|| a_BlockType == E_BLOCK_LEAVES
|
|
|
|
|
|| a_BlockType == E_BLOCK_LOG
|
|
|
|
|
|| a_BlockType == E_BLOCK_WOOL
|
|
|
|
|
|| a_BlockType == E_BLOCK_BOOKCASE
|
|
|
|
|
|| a_BlockType == E_BLOCK_FENCE
|
|
|
|
|
|| a_BlockType == E_BLOCK_TNT
|
|
|
|
|
|| a_BlockType == E_BLOCK_VINES;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 04:52:11 -04:00
|
|
|
|
bool cFireSimulator::FiresForever( BLOCKTYPE a_BlockType )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2012-10-03 04:52:11 -04:00
|
|
|
|
return a_BlockType != E_BLOCK_FIRE;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
bool cFireSimulator::BurnBlockAround(int a_X, int a_Y, int a_Z)
|
|
|
|
|
{
|
|
|
|
|
return BurnBlock(a_X + 1, a_Y, a_Z)
|
|
|
|
|
|| BurnBlock(a_X - 1, a_Y, a_Z)
|
|
|
|
|
|| BurnBlock(a_X, a_Y + 1, a_Z)
|
|
|
|
|
|| BurnBlock(a_X, a_Y - 1, a_Z)
|
|
|
|
|
|| BurnBlock(a_X, a_Y, a_Z + 1)
|
|
|
|
|
|| BurnBlock(a_X, a_Y, a_Z - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
bool cFireSimulator::BurnBlock(int a_X, int a_Y, int a_Z)
|
|
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
|
BLOCKTYPE BlockID = m_World.GetBlock(a_X, a_Y, a_Z);
|
|
|
|
|
if (IsBurnable(BlockID))
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
|
m_World.SetBlock(a_X, a_Y, a_Z, E_BLOCK_FIRE, 0);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-02-28 08:39:20 -05:00
|
|
|
|
if (IsForeverBurnable(BlockID))
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
|
BLOCKTYPE BlockAbove = m_World.GetBlock(a_X, a_Y + 1, a_Z);
|
|
|
|
|
if (BlockAbove == E_BLOCK_AIR)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-02-28 08:39:20 -05:00
|
|
|
|
m_World.SetBlock(a_X, a_Y + 1, a_Z, E_BLOCK_FIRE, 0); //Doesn<73>t notify the simulator so it won<6F>t go off
|
2012-06-14 09:06:06 -04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2012-10-13 05:53:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|