5 #include "../BlockInfo.h"
7 #include "../Defines.h"
10 #include "../Bindings/PluginManager.h"
18 #define FIRE_FLOG FLOGD
20 #define FIRE_FLOG(...)
27 #define MAX_CHANCE_REPLACE_FUEL 100000
28 #define MAX_CHANCE_FLAMMABILITY 100000
30 #define CHANCE_BASE_RAIN_EXTINGUISH 0.2
33 #define CHANCE_AGE_M_RAIN_EXTINGUISH 0.03
86 int NumMSecs =
static_cast<int>(a_Dt.count());
87 for (cCoordWithIntList::iterator itr = Data.begin(); itr != Data.end();)
89 Vector3i relPos(itr->x, itr->y, itr->z);
90 auto blockType = a_Chunk->
GetBlock(relPos);
95 FIRE_FLOG(
"FS: Removing block {0}", absPos);
96 itr = Data.erase(itr);
101 auto BlockMeta = a_Chunk->
GetMeta(relPos);
105 auto Adjusted = relPos + cc;
107 if ((Chunk !=
nullptr) && Chunk->IsValid())
109 return Chunk->IsWeatherWetAt(Adjusted);
118 itr = Data.erase(itr);
125 itr->Data -= NumMSecs;
141 itr = Data.erase(itr);
146 if (BlockMeta == 0x0f)
149 FIRE_FLOG(
"FS: Fire at {0} burnt out, removing the fire block", absPos);
152 itr = Data.erase(itr);
159 a_Chunk->
SetMeta(relPos, BlockMeta + 1);
162 itr->Data = BurnStep;
246 for (cCoordWithIntList::iterator itr = ChunkData.begin(), end = ChunkData.end(); itr != end; ++itr)
248 const Vector3i ItrPos{itr->
x, itr->y, itr->z};
249 if (ItrPos == a_Position)
254 if (itr->Data > NewBurnStep)
256 FIRE_FLOG(
"FS: Block lost its fuel at {0}", a_Block);
257 itr->Data = NewBurnStep;
264 FIRE_FLOG(
"FS: Adding block {0}", a_Block);
265 ChunkData.emplace_back(a_Position.
x, a_Position.
y, a_Position.
z, 100);
274 bool IsBlockBelowSolid =
false;
303 if (!IsBlockBelowSolid)
326 for (
int x = -1; x <= 1; x++)
328 for (
int z = -1; z <= 1; z++)
330 for (
int y = 1; y <= 2; y++)
341 auto dstRelPos = a_RelPos +
Vector3i{x, y, z};
350 FIRE_FLOG(
"FS: Starting new fire at {0}.", dstAbsPos);
366 auto relPos = a_RelPos + coord;
375 if ((neighbor ==
nullptr) || !neighbor->IsValid())
387 auto absPos = neighbor->RelativeToAbsolute(relPos);
@ E_BLOCK_OAK_WOOD_STAIRS
@ E_BLOCK_DOUBLE_WOODEN_SLAB
@ E_BLOCK_BIRCH_FENCE_GATE
@ E_BLOCK_ACACIA_FENCE_GATE
@ E_BLOCK_BIRCH_WOOD_STAIRS
@ E_BLOCK_JUNGLE_WOOD_STAIRS
@ E_BLOCK_SPRUCE_FENCE_GATE
@ E_BLOCK_SPRUCE_WOOD_STAIRS
@ E_BLOCK_DARK_OAK_FENCE_GATE
@ E_BLOCK_JUNGLE_FENCE_GATE
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
std::list< cCoordWithInt > cCoordWithIntList
unsigned char BLOCKTYPE
The datatype used by blockdata.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
static constexpr Vector3i gCrossCoords[]
static constexpr Vector3i gNeighborCoords[]
#define MAX_CHANCE_FLAMMABILITY
#define CHANCE_AGE_M_RAIN_EXTINGUISH
#define CHANCE_BASE_RAIN_EXTINGUISH
#define MAX_CHANCE_REPLACE_FUEL
cCoordWithIntList cFireSimulatorChunkData
Stores individual fire blocks in the chunk; the int data is used as the time [msec] the fire takes to...
Vector3< double > Vector3d
bool CallHookBlockSpread(cWorld &a_World, Vector3i a_BlockPos, eSpreadSource a_Source)
static bool IsSolid(BLOCKTYPE Block)
Is this block solid (player cannot walk through)?
cFireSimulatorChunkData & GetFireSimulatorData(void)
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition) const
Converts the coord relative to this chunk into an absolute coord.
cChunk * GetRelNeighborChunkAdjustCoords(Vector3i &a_RelPos) const
Returns the chunk into which the relatively-specified block belongs.
void SetBlock(Vector3i a_RelBlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
bool UnboundedRelSetBlock(Vector3i a_RelPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Same as SetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in ...
bool UnboundedRelGetBlock(Vector3i a_RelCoords, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Same as GetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in ...
void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta)
static bool IsValidHeight(Vector3i a_BlockPosition)
Validates a height-coordinate.
bool RandBool(double a_TrueProbability=0.5)
Return a random bool with the given probability of being true.
int GetValueSetI(const AString &keyname, const AString &valuename, const int defValue=0) override
cPluginManager * GetPluginManager(void)
unsigned m_BurnStepTimeNonfuel
Time (in msec) that a fire block takes to burn without a fuel block into the next step.
void RemoveFuelNeighbors(cChunk *a_Chunk, Vector3i a_RelPos)
Removes all burnable blocks neighboring the specified block.
int m_ReplaceFuelChance
Chance [0..100000] of a fuel burning out being replaced by a new fire block instead of an air block.
static bool IsFuel(BLOCKTYPE a_BlockType)
bool CanStartFireInBlock(cChunk *a_NearChunk, Vector3i a_RelPos)
Returns true if a fire can be started in the specified block, that is, it is an air block and has fue...
static bool IsAllowedBlock(BLOCKTYPE a_BlockType)
int m_Flammability
Chance [0..100000] of an adjacent fuel to catch fire on each tick.
virtual void AddBlock(cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) override
Called to simulate a new block.
void TrySpreadFire(cChunk *a_Chunk, Vector3i a_RelPos)
Tries to spread fire to a neighborhood of the specified block.
virtual void SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk *a_Chunk) override
unsigned m_BurnStepTimeFuel
Time (in msec) that a fire block takes to burn with a fuel block into the next step.
cFireSimulator(cWorld &a_World, cIniFile &a_IniFile)
int GetBurnStepTime(cChunk *a_Chunk, Vector3i a_RelPos)
Returns the time [msec] after which the specified fire block is stepped again; based on surrounding f...
static bool DoesBurnForever(BLOCKTYPE a_BlockType)
Base class for all block-based physics simulators (such as fluid, fire, falling blocks etc....
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
UInt32 SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec=80, double a_InitialVelocityCoeff=1, bool a_ShouldPlayFuseSound=true)