summaryrefslogtreecommitdiffstats
path: root/source/ChunkMap.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-18 21:09:51 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-18 21:09:51 +0200
commitb2138b132cc0f7bf03bdd723725729d76067ff23 (patch)
treed573bf041c1d47c7bf68cef49bae0be1d52ffc91 /source/ChunkMap.cpp
parentTNT fixes. (diff)
downloadcuberite-b2138b132cc0f7bf03bdd723725729d76067ff23.tar
cuberite-b2138b132cc0f7bf03bdd723725729d76067ff23.tar.gz
cuberite-b2138b132cc0f7bf03bdd723725729d76067ff23.tar.bz2
cuberite-b2138b132cc0f7bf03bdd723725729d76067ff23.tar.lz
cuberite-b2138b132cc0f7bf03bdd723725729d76067ff23.tar.xz
cuberite-b2138b132cc0f7bf03bdd723725729d76067ff23.tar.zst
cuberite-b2138b132cc0f7bf03bdd723725729d76067ff23.zip
Diffstat (limited to 'source/ChunkMap.cpp')
-rw-r--r--source/ChunkMap.cpp72
1 files changed, 35 insertions, 37 deletions
diff --git a/source/ChunkMap.cpp b/source/ChunkMap.cpp
index 1aa8dcb8b..d03919a85 100644
--- a/source/ChunkMap.cpp
+++ b/source/ChunkMap.cpp
@@ -1497,13 +1497,12 @@ bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback
-cVector3iArray * cChunkMap::DoExplosiontAt(float a_ExplosionSize, int a_BlockX, int a_BlockY, int a_BlockZ)
+void cChunkMap::DoExplosiontAt(float a_ExplosionSize, int a_BlockX, int a_BlockY, int a_BlockZ, cVector3iArray & a_BlocksAffected)
{
cBlockArea area;
- cVector3iArray * BlocksAffected = new cVector3iArray();
int ExplosionSizeInt = (int) ceil(a_ExplosionSize);
int ExplosionSizeSq = ExplosionSizeInt * ExplosionSizeInt;
- BlocksAffected->reserve(8 * ExplosionSizeInt * ExplosionSizeInt * ExplosionSizeInt);
+ a_BlocksAffected.reserve(8 * ExplosionSizeInt * ExplosionSizeInt * ExplosionSizeInt);
area.Read(m_World, a_BlockX - ExplosionSizeInt, a_BlockX + ExplosionSizeInt, a_BlockY - ExplosionSizeInt, a_BlockY + ExplosionSizeInt, a_BlockZ - ExplosionSizeInt,a_BlockZ + ExplosionSizeInt);
for (int x = -ExplosionSizeInt; x < ExplosionSizeInt; x++)
{
@@ -1516,43 +1515,42 @@ cVector3iArray * cChunkMap::DoExplosiontAt(float a_ExplosionSize, int a_BlockX,
}
for (int z = -ExplosionSizeInt; z < ExplosionSizeInt; z++)
{
- if ((x * x + y * y + z * z) < ExplosionSizeSq)
+ if ((x * x + y * y + z * z) > ExplosionSizeSq)
{
- switch (area.GetBlockType(a_BlockX + x, a_BlockY + y, a_BlockZ + z))
+ // Too far away
+ continue;
+ }
+ switch (area.GetBlockType(a_BlockX + x, a_BlockY + y, a_BlockZ + z))
+ {
+ case E_BLOCK_TNT:
{
- case E_BLOCK_TNT:
- {
- // Activate the TNT, with a random fuse between 10 to 30 game ticks
- float FuseTime = (float)(10 + m_World->GetTickRandomNumber(20)) / 20;
- cTNTEntity * TNT = new cTNTEntity(a_BlockX, a_BlockY, a_BlockZ, FuseTime);
- TNT->Initialize(m_World);
- area.SetBlockType(a_BlockX + x, a_BlockY + y, a_BlockZ + z, E_BLOCK_AIR);
- BlocksAffected->push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ + z));
- break;
- }
- case E_BLOCK_OBSIDIAN:
- case E_BLOCK_BEDROCK:
- case E_BLOCK_WATER:
- case E_BLOCK_STATIONARY_WATER:
- case E_BLOCK_STATIONARY_LAVA:
- case E_BLOCK_LAVA:
- {
- // These blocks are not affected by explosions
- break;
- }
- default:
- {
- area.SetBlockType(a_BlockX + x, a_BlockY + y, a_BlockZ + z, E_BLOCK_AIR);
- BlocksAffected->push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ + z));
- }
+ // Activate the TNT, with a random fuse between 10 to 30 game ticks
+ float FuseTime = (float)(10 + m_World->GetTickRandomNumber(20)) / 20;
+ m_World->SpawnPrimedTNT(a_BlockX + x + 0.5, a_BlockY + y + 0.5, a_BlockZ + z + 0.5, FuseTime);
+ area.SetBlockType(a_BlockX + x, a_BlockY + y, a_BlockZ + z, E_BLOCK_AIR);
+ a_BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ + z));
+ break;
}
- }
- }
- }
-
- }
- area.Write(m_World,a_BlockX - ExplosionSizeInt,a_BlockY - ExplosionSizeInt,a_BlockZ - ExplosionSizeInt);
- return BlocksAffected;
+ case E_BLOCK_OBSIDIAN:
+ case E_BLOCK_BEDROCK:
+ case E_BLOCK_WATER:
+ case E_BLOCK_STATIONARY_WATER:
+ case E_BLOCK_STATIONARY_LAVA:
+ case E_BLOCK_LAVA:
+ {
+ // These blocks are not affected by explosions
+ break;
+ }
+ default:
+ {
+ area.SetBlockType(a_BlockX + x, a_BlockY + y, a_BlockZ + z, E_BLOCK_AIR);
+ a_BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ + z));
+ }
+ } // switch (BlockType)
+ } // for z
+ } // for y
+ } // for x
+ area.Write(m_World, a_BlockX - ExplosionSizeInt, a_BlockY - ExplosionSizeInt, a_BlockZ - ExplosionSizeInt);
}