diff options
Diffstat (limited to '')
-rw-r--r-- | source/ChunkMap.cpp | 30 | ||||
-rw-r--r-- | source/ChunkMap.h | 3 | ||||
-rw-r--r-- | source/World.cpp | 35 |
3 files changed, 37 insertions, 31 deletions
diff --git a/source/ChunkMap.cpp b/source/ChunkMap.cpp index 7a7eeb25a..3e9fd4a81 100644 --- a/source/ChunkMap.cpp +++ b/source/ChunkMap.cpp @@ -1450,6 +1450,36 @@ 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) +{ + cBlockArea area; + cVector3iArray *BlocksAffected = new cVector3iArray(); + int ExplosionSizeInt = (int) ceil(a_ExplosionSize); + 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++) + { + for (int y = -ExplosionSizeInt; y < ExplosionSizeInt; y++) + { + for (int z = -ExplosionSizeInt; z < ExplosionSizeInt; z++) + { + if ((x*x + y*y + z*z) < (ExplosionSizeInt * ExplosionSizeInt)) + { + 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)); + } + } + } + + } + area.Write(m_World,a_BlockX - ExplosionSizeInt,a_BlockY - ExplosionSizeInt,a_BlockZ - ExplosionSizeInt); + return BlocksAffected; +} + + + + + bool cChunkMap::DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback) { cCSLock Lock(m_CSLayers); diff --git a/source/ChunkMap.h b/source/ChunkMap.h index e3dfdc88f..a2fb5abff 100644 --- a/source/ChunkMap.h +++ b/source/ChunkMap.h @@ -197,6 +197,9 @@ public: /// Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback); // Lua-accessible + + // Destroys and returns a list of blocks destroyed in the explosion at the specified coordinates + cVector3iArray * DoExplosiontAt(float a_ExplosionSize, int a_BlockX, int a_BlockY, int a_BlockZ); /// Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found and callback returned false. bool DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback); // Lua-accessible diff --git a/source/World.cpp b/source/World.cpp index 418f078eb..b10f68554 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -705,37 +705,9 @@ bool cWorld::ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback void cWorld::DoExplosiontAt(float a_ExplosionSize, int a_BlockX, int a_BlockY, int a_BlockZ) { - // TODO: implement explosion using cBlockArea / in cChunkMap, add damage to entities, add support for pickups, and implement block hardiness + // TODO: Add damage to entities, add support for pickups, and implement block hardiness Vector3d explosion_pos = Vector3d(a_BlockX,a_BlockY,a_BlockZ); - cVector3iArray BlocksAffected; - int ExplosionSizeInt = (int)a_ExplosionSize; - BlocksAffected.reserve(8 * ExplosionSizeInt * ExplosionSizeInt * ExplosionSizeInt); - for (int x = 0; x < ExplosionSizeInt; x++) - { - for (int y = 0; y < ExplosionSizeInt; y++) - { - for (int z = 0; z < ExplosionSizeInt; z++) - { - DigBlock(a_BlockX + x, a_BlockY + y, a_BlockZ + z); - DigBlock(a_BlockX + x, a_BlockY - y, a_BlockZ + z); - DigBlock(a_BlockX - x, a_BlockY - y, a_BlockZ - z); - DigBlock(a_BlockX - x, a_BlockY + y, a_BlockZ - z); - DigBlock(a_BlockX + x, a_BlockY + y, a_BlockZ - z); - DigBlock(a_BlockX + x, a_BlockY - y, a_BlockZ - z); - DigBlock(a_BlockX - x, a_BlockY + y, a_BlockZ + z); - DigBlock(a_BlockX - x, a_BlockY - y, a_BlockZ + z); - BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ + z)); - BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY - y, a_BlockZ + z)); - BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY - y, a_BlockZ - z)); - BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY + y, a_BlockZ - z)); - BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY + y, a_BlockZ - z)); - BlocksAffected.push_back(Vector3i(a_BlockX + x, a_BlockY - y, a_BlockZ - z)); - BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY + y, a_BlockZ + z)); - BlocksAffected.push_back(Vector3i(a_BlockX - x, a_BlockY - y, a_BlockZ + z)); - } - } - - } + cVector3iArray * BlocksAffected = m_ChunkMap->DoExplosiontAt(a_ExplosionSize,a_BlockX,a_BlockY,a_BlockZ); BroadcastSoundEffect("random.explode", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 1.0f, 0.6f); { cCSLock Lock(m_CSPlayers); @@ -757,10 +729,11 @@ void cWorld::DoExplosiontAt(float a_ExplosionSize, int a_BlockX, int a_BlockY, i } distance_explosion.Normalize(); distance_explosion *= power; - ch->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_ExplosionSize, BlocksAffected, distance_explosion); + ch->SendExplosion(a_BlockX, a_BlockY, a_BlockZ, a_ExplosionSize, *BlocksAffected, distance_explosion); } } } + delete BlocksAffected; } |