2012-01-29 14:28:19 -05:00
|
|
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
2011-12-28 16:00:35 -05:00
|
|
|
|
#include "cFireSimulator.h"
|
|
|
|
|
#include "cWorld.h"
|
|
|
|
|
#include "Vector3i.h"
|
|
|
|
|
#include "BlockID.h"
|
|
|
|
|
#include "Defines.h"
|
|
|
|
|
|
|
|
|
|
cFireSimulator::cFireSimulator( cWorld* a_World )
|
|
|
|
|
: cSimulator(a_World)
|
2012-02-14 07:29:39 -05:00
|
|
|
|
, m_Blocks(new BlockList)
|
|
|
|
|
, m_Buffer(new BlockList)
|
|
|
|
|
, m_BurningBlocks(new BlockList)
|
2011-12-28 16:00:35 -05:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cFireSimulator::~cFireSimulator()
|
|
|
|
|
{
|
|
|
|
|
delete m_Buffer;
|
|
|
|
|
delete m_Blocks;
|
|
|
|
|
delete m_BurningBlocks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cFireSimulator::Simulate( float a_Dt )
|
|
|
|
|
{
|
|
|
|
|
m_Buffer->clear();
|
|
|
|
|
std::swap( m_Blocks, m_Buffer );
|
|
|
|
|
|
2012-02-14 07:29:39 -05:00
|
|
|
|
for( BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr )
|
2011-12-28 16:00:35 -05:00
|
|
|
|
{
|
2012-02-14 07:29:39 -05:00
|
|
|
|
Vector3i Pos = *itr;
|
2011-12-28 16:00:35 -05:00
|
|
|
|
|
2012-02-14 07:29:39 -05:00
|
|
|
|
char BlockID = m_World->GetBlock(Pos.x, Pos.y, Pos.z);
|
2011-12-28 19:44:19 -05:00
|
|
|
|
|
|
|
|
|
if(!IsAllowedBlock(BlockID)) //Check wheather the block is still burning
|
2011-12-28 16:00:35 -05:00
|
|
|
|
continue;
|
|
|
|
|
|
2012-02-14 07:29:39 -05:00
|
|
|
|
if(BurnBlockAround(Pos.x, Pos.y, Pos.z)) //Burn single block and if there was one -> next time again
|
|
|
|
|
_AddBlock(Pos.x, Pos.y, Pos.z);
|
2011-12-28 16:00:35 -05:00
|
|
|
|
else
|
2012-02-14 07:29:39 -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);
|
2011-12-28 16:00:35 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cFireSimulator::IsAllowedBlock( char a_BlockID )
|
|
|
|
|
{
|
|
|
|
|
return a_BlockID == E_BLOCK_FIRE
|
|
|
|
|
|| IsBlockLava(a_BlockID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cFireSimulator::AddBlock(int a_X, int a_Y, int a_Z)
|
|
|
|
|
{
|
|
|
|
|
char BlockID = m_World->GetBlock(a_X, a_Y, a_Z);
|
|
|
|
|
if(!IsAllowedBlock(BlockID)) //This should save very much time because it doesn<73>t have to iterate through all blocks
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//check for duplicates
|
2012-02-14 07:29:39 -05:00
|
|
|
|
for( BlockList::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr )
|
2011-12-28 16:00:35 -05:00
|
|
|
|
{
|
2012-02-14 07:29:39 -05:00
|
|
|
|
Vector3i Pos = *itr;
|
|
|
|
|
if( Pos.x == a_X && Pos.y == a_Y && Pos.z == a_Z )
|
2011-12-28 16:00:35 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_AddBlock(a_X, a_Y, a_Z);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cFireSimulator::_AddBlock(int a_X, int a_Y, int a_Z)
|
|
|
|
|
{
|
2012-02-14 07:29:39 -05:00
|
|
|
|
m_Blocks->push_back( Vector3i(a_X, a_Y, a_Z) );
|
2011-12-28 16:00:35 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool cFireSimulator::IsForeverBurnable( char a_BlockID )
|
|
|
|
|
{
|
|
|
|
|
return a_BlockID == E_BLOCK_BLOODSTONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool cFireSimulator::IsBurnable( char a_BlockID )
|
|
|
|
|
{
|
2012-05-25 03:18:52 -04:00
|
|
|
|
return a_BlockID == E_BLOCK_PLANKS
|
2011-12-28 16:00:35 -05:00
|
|
|
|
|| a_BlockID == E_BLOCK_LEAVES
|
|
|
|
|
|| a_BlockID == E_BLOCK_LOG
|
|
|
|
|
|| a_BlockID == E_BLOCK_WHITE_CLOTH
|
|
|
|
|
|| a_BlockID == E_BLOCK_BOOKCASE
|
|
|
|
|
|| a_BlockID == E_BLOCK_FENCE
|
|
|
|
|
|| a_BlockID == E_BLOCK_TNT;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 19:44:19 -05:00
|
|
|
|
bool cFireSimulator::FiresForever( char a_BlockID )
|
|
|
|
|
{
|
|
|
|
|
return a_BlockID != E_BLOCK_FIRE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 16:00:35 -05: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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool cFireSimulator::BurnBlock(int a_X, int a_Y, int a_Z)
|
|
|
|
|
{
|
|
|
|
|
char BlockID = m_World->GetBlock(a_X, a_Y, a_Z);
|
|
|
|
|
if(IsBurnable(BlockID))
|
|
|
|
|
{
|
|
|
|
|
m_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_FIRE, 0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if(IsForeverBurnable(BlockID))
|
|
|
|
|
{
|
|
|
|
|
char BlockAbove = m_World->GetBlock(a_X, a_Y + 1, a_Z);
|
|
|
|
|
if(BlockAbove == E_BLOCK_AIR)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|