2014-03-10 14:23:12 -04:00
|
|
|
|
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"
|
2013-03-01 14:35:29 -05:00
|
|
|
#include "../Chunk.h"
|
2014-03-16 09:38:41 -04:00
|
|
|
#include "Root.h"
|
2014-03-28 11:44:12 -04:00
|
|
|
#include "../Bindings/PluginManager.h"
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
// Easy switch for turning on debugging logging:
|
|
|
|
#if 0
|
|
|
|
#define FLOG LOGD
|
|
|
|
#else
|
|
|
|
#define FLOG(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_CHANCE_REPLACE_FUEL 100000
|
|
|
|
#define MAX_CHANCE_FLAMMABILITY 100000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
int x, y, z;
|
|
|
|
} gCrossCoords[] =
|
|
|
|
{
|
|
|
|
{ 1, 0, 0},
|
|
|
|
{-1, 0, 0},
|
|
|
|
{ 0, 0, 1},
|
|
|
|
{ 0, 0, -1},
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
int x, y, z;
|
|
|
|
} gNeighborCoords[] =
|
|
|
|
{
|
|
|
|
{ 1, 0, 0},
|
|
|
|
{-1, 0, 0},
|
|
|
|
{ 0, 1, 0},
|
|
|
|
{ 0, -1, 0},
|
|
|
|
{ 0, 0, 1},
|
|
|
|
{ 0, 0, -1},
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-03-01 14:35:29 -05:00
|
|
|
// cFireSimulator:
|
|
|
|
|
|
|
|
cFireSimulator::cFireSimulator(cWorld & a_World, cIniFile & a_IniFile) :
|
|
|
|
cSimulator(a_World)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
// Read params from the ini file:
|
|
|
|
m_BurnStepTimeFuel = a_IniFile.GetValueSetI("FireSimulator", "BurnStepTimeFuel", 500);
|
|
|
|
m_BurnStepTimeNonfuel = a_IniFile.GetValueSetI("FireSimulator", "BurnStepTimeNonfuel", 100);
|
|
|
|
m_Flammability = a_IniFile.GetValueSetI("FireSimulator", "Flammability", 50);
|
|
|
|
m_ReplaceFuelChance = a_IniFile.GetValueSetI("FireSimulator", "ReplaceFuelChance", 50000);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cFireSimulator::~cFireSimulator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
void cFireSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
cCoordWithIntList & Data = a_Chunk->GetFireSimulatorData();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
int NumMSecs = (int)a_Dt;
|
|
|
|
for (cCoordWithIntList::iterator itr = Data.begin(); itr != Data.end();)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-04-26 13:50:23 -04:00
|
|
|
int x = itr->x;
|
|
|
|
int y = itr->y;
|
|
|
|
int z = itr->z;
|
2014-07-19 08:53:41 -04:00
|
|
|
BLOCKTYPE BlockType = a_Chunk->GetBlock(x, y, z);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
if (!IsAllowedBlock(BlockType))
|
2013-02-28 08:39:20 -05:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
// The block is no longer eligible (not a fire block anymore; a player probably placed a block over the fire)
|
|
|
|
FLOG("FS: Removing block {%d, %d, %d}",
|
|
|
|
itr->x + a_ChunkX * cChunkDef::Width, itr->y, itr->z + a_ChunkZ * cChunkDef::Width
|
|
|
|
);
|
|
|
|
itr = Data.erase(itr);
|
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
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
// Try to spread the fire:
|
|
|
|
TrySpreadFire(a_Chunk, itr->x, itr->y, itr->z);
|
|
|
|
|
|
|
|
itr->Data -= NumMSecs;
|
|
|
|
if (itr->Data >= 0)
|
2012-10-14 13:06:21 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
// Not yet, wait for it longer
|
|
|
|
++itr;
|
|
|
|
continue;
|
2012-10-14 13:06:21 -04:00
|
|
|
}
|
2013-03-01 14:35:29 -05:00
|
|
|
|
|
|
|
// Burn out the fire one step by increasing the meta:
|
|
|
|
/*
|
|
|
|
FLOG("FS: Fire at {%d, %d, %d} is stepping",
|
|
|
|
itr->x + a_ChunkX * cChunkDef::Width, itr->y, itr->z + a_ChunkZ * cChunkDef::Width
|
|
|
|
);
|
|
|
|
*/
|
2014-04-26 13:50:23 -04:00
|
|
|
NIBBLETYPE BlockMeta = a_Chunk->GetMeta(x, y, z);
|
2013-03-01 14:35:29 -05:00
|
|
|
if (BlockMeta == 0x0f)
|
2013-02-28 08:39:20 -05:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
// The fire burnt out completely
|
|
|
|
FLOG("FS: Fire at {%d, %d, %d} burnt out, removing the fire block",
|
|
|
|
itr->x + a_ChunkX * cChunkDef::Width, itr->y, itr->z + a_ChunkZ * cChunkDef::Width
|
|
|
|
);
|
|
|
|
a_Chunk->SetBlock(itr->x, itr->y, itr->z, E_BLOCK_AIR, 0);
|
|
|
|
RemoveFuelNeighbors(a_Chunk, itr->x, itr->y, itr->z);
|
|
|
|
itr = Data.erase(itr);
|
|
|
|
continue;
|
2013-02-28 08:39:20 -05:00
|
|
|
}
|
2013-12-03 21:05:34 -05:00
|
|
|
|
2014-07-20 17:10:31 -04:00
|
|
|
if ((itr->y > 0) && (!DoesBurnForever(a_Chunk->GetBlock(itr->x, itr->y - 1, itr->z))))
|
2013-12-02 16:11:45 -05:00
|
|
|
{
|
2014-04-26 13:50:23 -04:00
|
|
|
a_Chunk->SetMeta(x, y, z, BlockMeta + 1);
|
2013-12-02 16:11:45 -05:00
|
|
|
}
|
2013-03-01 14:35:29 -05:00
|
|
|
itr->Data = GetBurnStepTime(a_Chunk, itr->x, itr->y, itr->z); // TODO: Add some randomness into this
|
|
|
|
} // for itr - Data[]
|
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
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
return (a_BlockType == E_BLOCK_FIRE);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
bool cFireSimulator::IsFuel(BLOCKTYPE a_BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
switch (a_BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
case E_BLOCK_PLANKS:
|
2014-02-28 09:26:32 -05:00
|
|
|
case E_BLOCK_DOUBLE_WOODEN_SLAB:
|
|
|
|
case E_BLOCK_WOODEN_SLAB:
|
|
|
|
case E_BLOCK_WOODEN_STAIRS:
|
|
|
|
case E_BLOCK_SPRUCE_WOOD_STAIRS:
|
|
|
|
case E_BLOCK_BIRCH_WOOD_STAIRS:
|
|
|
|
case E_BLOCK_JUNGLE_WOOD_STAIRS:
|
2013-03-01 14:35:29 -05:00
|
|
|
case E_BLOCK_LEAVES:
|
2014-02-28 09:26:32 -05:00
|
|
|
case E_BLOCK_NEW_LEAVES:
|
2013-03-01 14:35:29 -05:00
|
|
|
case E_BLOCK_LOG:
|
2014-02-28 09:26:32 -05:00
|
|
|
case E_BLOCK_NEW_LOG:
|
2013-03-01 14:35:29 -05:00
|
|
|
case E_BLOCK_WOOL:
|
|
|
|
case E_BLOCK_BOOKCASE:
|
|
|
|
case E_BLOCK_FENCE:
|
|
|
|
case E_BLOCK_TNT:
|
|
|
|
case E_BLOCK_VINES:
|
2014-02-20 11:56:35 -05:00
|
|
|
case E_BLOCK_HAY_BALE:
|
2014-02-28 09:26:32 -05:00
|
|
|
case E_BLOCK_TALL_GRASS:
|
|
|
|
case E_BLOCK_BIG_FLOWER:
|
|
|
|
case E_BLOCK_DANDELION:
|
|
|
|
case E_BLOCK_FLOWER:
|
|
|
|
case E_BLOCK_CARPET:
|
2012-10-14 13:06:21 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
return true;
|
2012-10-14 13:06:21 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-03-01 14:35:29 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
|
|
|
|
|
2013-12-03 21:05:34 -05:00
|
|
|
bool cFireSimulator::DoesBurnForever(BLOCKTYPE a_BlockType)
|
2013-03-01 14:35:29 -05:00
|
|
|
{
|
|
|
|
return (a_BlockType == E_BLOCK_NETHERRACK);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-01 14:35:29 -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-07-22 15:54:27 -04:00
|
|
|
if ((a_Chunk == NULL) || !a_Chunk->IsValid())
|
2013-03-03 09:25:27 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
int RelX = a_BlockX - a_Chunk->GetPosX() * cChunkDef::Width;
|
|
|
|
int RelZ = a_BlockZ - a_Chunk->GetPosZ() * cChunkDef::Width;
|
|
|
|
BLOCKTYPE BlockType = a_Chunk->GetBlock(RelX, a_BlockY, RelZ);
|
|
|
|
if (!IsAllowedBlock(BlockType))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for duplicates:
|
|
|
|
cFireSimulatorChunkData & ChunkData = a_Chunk->GetFireSimulatorData();
|
|
|
|
for (cCoordWithIntList::iterator itr = ChunkData.begin(), end = ChunkData.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
if ((itr->x == RelX) && (itr->y == a_BlockY) && (itr->z == RelZ))
|
|
|
|
{
|
|
|
|
// Already present, skip adding
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} // for itr - ChunkData[]
|
|
|
|
|
|
|
|
FLOG("FS: Adding block {%d, %d, %d}", a_BlockX, a_BlockY, a_BlockZ);
|
|
|
|
ChunkData.push_back(cCoordWithInt(RelX, a_BlockY, RelZ, 100));
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
int cFireSimulator::GetBurnStepTime(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-10-09 03:09:47 -04:00
|
|
|
bool IsBlockBelowSolid = false;
|
2013-09-30 16:15:48 -04:00
|
|
|
if (a_RelY > 0)
|
2013-03-01 14:35:29 -05:00
|
|
|
{
|
|
|
|
BLOCKTYPE BlockBelow = a_Chunk->GetBlock(a_RelX, a_RelY - 1, a_RelZ);
|
2013-12-03 21:05:34 -05:00
|
|
|
if (DoesBurnForever(BlockBelow))
|
2013-03-01 14:35:29 -05:00
|
|
|
{
|
|
|
|
// Is burning atop of netherrack, burn forever (re-check in 10 sec)
|
|
|
|
return 10000;
|
|
|
|
}
|
|
|
|
if (IsFuel(BlockBelow))
|
|
|
|
{
|
|
|
|
return m_BurnStepTimeFuel;
|
|
|
|
}
|
2014-03-01 14:34:19 -05:00
|
|
|
IsBlockBelowSolid = cBlockInfo::IsSolid(BlockBelow);
|
2013-03-01 14:35:29 -05:00
|
|
|
}
|
|
|
|
|
2013-12-20 10:01:34 -05:00
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
|
2013-03-01 14:35:29 -05:00
|
|
|
{
|
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
|
|
|
if (a_Chunk->UnboundedRelGetBlock(a_RelX + gCrossCoords[i].x, a_RelY, a_RelZ + gCrossCoords[i].z, BlockType, BlockMeta))
|
|
|
|
{
|
|
|
|
if (IsFuel(BlockType))
|
|
|
|
{
|
|
|
|
return m_BurnStepTimeFuel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // for i - gCrossCoords[]
|
2013-09-29 18:39:58 -04:00
|
|
|
|
2013-10-09 03:09:47 -04:00
|
|
|
if (!IsBlockBelowSolid && (a_RelY >= 0))
|
2013-09-29 18:39:58 -04:00
|
|
|
{
|
|
|
|
// Checked through everything, nothing was flammable
|
2013-10-09 03:09:47 -04:00
|
|
|
// If block below isn't solid, we can't have fire, it would be a non-fueled fire
|
|
|
|
// SetBlock just to make sure fire doesn't spawn
|
|
|
|
a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_AIR, 0);
|
|
|
|
return 0;
|
2013-09-29 18:39:58 -04:00
|
|
|
}
|
2013-10-09 03:09:47 -04:00
|
|
|
return m_BurnStepTimeNonfuel;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
/*
|
|
|
|
if (m_World.GetTickRandomNumber(10000) > 100)
|
|
|
|
{
|
|
|
|
// Make the chance to spread 100x smaller
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (int x = a_RelX - 1; x <= a_RelX + 1; x++)
|
|
|
|
{
|
|
|
|
for (int z = a_RelZ - 1; z <= a_RelZ + 1; z++)
|
|
|
|
{
|
|
|
|
for (int y = a_RelY - 1; y <= a_RelY + 2; y++) // flames spread up one more block than around
|
|
|
|
{
|
|
|
|
// No need to check the coords for equality with the parent block,
|
|
|
|
// it cannot catch fire anyway (because it's not an air block)
|
|
|
|
|
2014-07-17 16:50:58 -04:00
|
|
|
if (m_World.GetTickRandomNumber(MAX_CHANCE_FLAMMABILITY) > m_Flammability)
|
2013-03-01 14:35:29 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the fire in the neighbor {x, y, z}
|
|
|
|
/*
|
2014-07-17 16:50:58 -04:00
|
|
|
FLOG("FS: Trying to start fire at {%d, %d, %d}.",
|
2013-03-01 14:35:29 -05:00
|
|
|
x + a_Chunk->GetPosX() * cChunkDef::Width, y, z + a_Chunk->GetPosZ() * cChunkDef::Width
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
if (CanStartFireInBlock(a_Chunk, x, y, z))
|
|
|
|
{
|
2014-03-16 09:38:41 -04:00
|
|
|
int a_PosX = x + a_Chunk->GetPosX() * cChunkDef::Width;
|
|
|
|
int a_PosZ = z + a_Chunk->GetPosZ() * cChunkDef::Width;
|
|
|
|
|
2014-03-16 17:28:12 -04:00
|
|
|
if (cRoot::Get()->GetPluginManager()->CallHookBlockSpread(&m_World, a_PosX, y, a_PosZ, ssFireSpread))
|
2014-03-16 09:38:41 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FLOG("FS: Starting new fire at {%d, %d, %d}.", a_PosX, y, a_PosZ);
|
2013-03-01 14:35:29 -05:00
|
|
|
a_Chunk->UnboundedRelSetBlock(x, y, z, E_BLOCK_FIRE, 0);
|
|
|
|
}
|
|
|
|
} // for y
|
|
|
|
} // for z
|
|
|
|
} // for x
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-12-20 10:01:34 -05:00
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(gNeighborCoords); i++)
|
2013-03-01 14:35:29 -05:00
|
|
|
{
|
|
|
|
BLOCKTYPE BlockType;
|
2014-03-08 20:23:55 -05:00
|
|
|
int X = a_RelX + gNeighborCoords[i].x;
|
|
|
|
int Z = a_RelZ + gNeighborCoords[i].z;
|
|
|
|
|
|
|
|
cChunkPtr Neighbour = a_Chunk->GetRelNeighborChunkAdjustCoords(X, Z);
|
|
|
|
if (Neighbour == NULL)
|
2013-03-01 14:35:29 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2014-04-18 15:09:44 -04:00
|
|
|
BlockType = Neighbour->GetBlock(X, a_RelY + gNeighborCoords[i].y, Z);
|
2014-03-08 20:23:55 -05:00
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
if (!IsFuel(BlockType))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2014-03-08 20:23:55 -05:00
|
|
|
|
|
|
|
if (BlockType == E_BLOCK_TNT)
|
|
|
|
{
|
|
|
|
int AbsX = X + Neighbour->GetPosX() * cChunkDef::Width;
|
|
|
|
int AbsZ = Z + Neighbour->GetPosZ() * cChunkDef::Width;
|
|
|
|
|
|
|
|
m_World.SpawnPrimedTNT(AbsX, a_RelY + gNeighborCoords[i].y, AbsZ, 0);
|
|
|
|
Neighbour->SetBlock(X, a_RelY + gNeighborCoords[i].y, Z, E_BLOCK_AIR, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
bool ShouldReplaceFuel = (m_World.GetTickRandomNumber(MAX_CHANCE_REPLACE_FUEL) < m_ReplaceFuelChance);
|
2014-03-08 20:23:55 -05:00
|
|
|
Neighbour->SetBlock(X, a_RelY + gNeighborCoords[i].y, Z, ShouldReplaceFuel ? E_BLOCK_FIRE : E_BLOCK_AIR, 0);
|
2013-03-01 14:35:29 -05:00
|
|
|
} // for i - Coords[]
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-01 14:35:29 -05:00
|
|
|
bool cFireSimulator::CanStartFireInBlock(cChunk * a_NearChunk, int a_RelX, int a_RelY, int a_RelZ)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
|
|
|
if (!a_NearChunk->UnboundedRelGetBlock(a_RelX, a_RelY, a_RelZ, BlockType, BlockMeta))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
// The chunk is not accessible
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BlockType != E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
// Only an air block can be replaced by a fire block
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-03-01 14:35:29 -05:00
|
|
|
|
2013-12-20 10:01:34 -05:00
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(gNeighborCoords); i++)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-01 14:35:29 -05:00
|
|
|
if (!a_NearChunk->UnboundedRelGetBlock(a_RelX + gNeighborCoords[i].x, a_RelY + gNeighborCoords[i].y, a_RelZ + gNeighborCoords[i].z, BlockType, BlockMeta))
|
|
|
|
{
|
|
|
|
// Neighbor inaccessible, skip it while evaluating
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (IsFuel(BlockType))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-01 14:35:29 -05:00
|
|
|
} // for i - Coords[]
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-10-13 05:53:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|