diff options
author | 12xx12 <44411062+12xx12@users.noreply.github.com> | 2020-10-08 21:13:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 21:13:44 +0200 |
commit | 3381c0f6d6671a485283c889b036c0a431e2a2b9 (patch) | |
tree | bf32b4d9c8d8e6c4c8d232ca6ad16975ee6d17c6 /src/Physics | |
parent | Fix cmake not adding Werror on clang, and _lots_ of warnings (#4963) (diff) | |
download | cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.gz cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.bz2 cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.lz cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.xz cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.tar.zst cuberite-3381c0f6d6671a485283c889b036c0a431e2a2b9.zip |
Diffstat (limited to 'src/Physics')
-rw-r--r-- | src/Physics/Explodinator.cpp | 34 | ||||
-rw-r--r-- | src/Physics/Explodinator.h | 5 |
2 files changed, 20 insertions, 19 deletions
diff --git a/src/Physics/Explodinator.cpp b/src/Physics/Explodinator.cpp index d68dc8541..1c6d61949 100644 --- a/src/Physics/Explodinator.cpp +++ b/src/Physics/Explodinator.cpp @@ -102,7 +102,7 @@ namespace Explodinator } /** Sets the block at the given position, updating surroundings. */ - static void DestroyBlock(cWorld & a_World, cChunk & a_Chunk, const Vector3i a_AbsolutePosition, const Vector3i a_RelativePosition, const BLOCKTYPE a_DestroyedBlock, const BLOCKTYPE a_NewBlock) + static void DestroyBlock(cWorld & a_World, cChunk & a_Chunk, const Vector3i a_AbsolutePosition, const Vector3i a_RelativePosition, const BLOCKTYPE a_DestroyedBlock, const BLOCKTYPE a_NewBlock, const cEntity * const a_ExplodingEntity) { const auto DestroyedMeta = a_Chunk.GetMeta(a_RelativePosition); @@ -113,12 +113,12 @@ namespace Explodinator a_Chunk.SetBlock(a_RelativePosition, a_NewBlock, 0); cChunkInterface Interface(a_World.GetChunkMap()); - cBlockHandler::For(a_DestroyedBlock).OnBroken(Interface, a_World, a_AbsolutePosition, a_DestroyedBlock, DestroyedMeta); + cBlockHandler::For(a_DestroyedBlock).OnBroken(Interface, a_World, a_AbsolutePosition, a_DestroyedBlock, DestroyedMeta, a_ExplodingEntity); } /** Sets the block at the given Position to air, updates surroundings, and spawns pickups, fire, shrapnel according to Minecraft rules. OK, _mostly_ Minecraft rules. */ - static void DestroyBlock(cChunk & a_Chunk, const Vector3i a_Position, const unsigned a_Power, const bool a_Fiery) + static void DestroyBlock(cChunk & a_Chunk, const Vector3i a_Position, const unsigned a_Power, const bool a_Fiery, const cEntity * const a_ExplodingEntity) { const auto DestroyedBlock = a_Chunk.GetBlock(a_Position); if (DestroyedBlock == E_BLOCK_AIR) @@ -150,7 +150,7 @@ namespace Explodinator if ((Below.y >= 0) && cBlockInfo::FullyOccupiesVoxel(a_Chunk.GetBlock(Below))) { // Start a fire: - DestroyBlock(World, a_Chunk, Absolute, a_Position, DestroyedBlock, E_BLOCK_FIRE); + DestroyBlock(World, a_Chunk, Absolute, a_Position, DestroyedBlock, E_BLOCK_FIRE, a_ExplodingEntity); return; } } @@ -169,11 +169,11 @@ namespace Explodinator } } - DestroyBlock(World, a_Chunk, Absolute, a_Position, DestroyedBlock, E_BLOCK_AIR); + DestroyBlock(World, a_Chunk, Absolute, a_Position, DestroyedBlock, E_BLOCK_AIR, a_ExplodingEntity); } /** Traces the path taken by one Explosion Lazor (tm) with given direction and intensity, that will destroy blocks until it is exhausted. */ - static void DestructionTrace(cChunk * a_Chunk, Vector3f a_Origin, const Vector3f a_Destination, const unsigned a_Power, const bool a_Fiery, float a_Intensity) + static void DestructionTrace(cChunk * a_Chunk, Vector3f a_Origin, const Vector3f a_Destination, const unsigned a_Power, const bool a_Fiery, float a_Intensity, const cEntity * const a_ExplodingEntity) { // The current position the ray is at. auto Checkpoint = a_Origin; @@ -206,7 +206,7 @@ namespace Explodinator break; } - DestroyBlock(*Neighbour, Position, a_Power, a_Fiery); + DestroyBlock(*Neighbour, Position, a_Power, a_Fiery, a_ExplodingEntity); // Adjust coordinates to be relative to the neighbour chunk: Checkpoint = RebaseRelativePosition(a_Chunk->GetPos(), Neighbour->GetPos(), Checkpoint); @@ -220,7 +220,7 @@ namespace Explodinator } /** Sends out Explosion Lazors (tm) originating from the given position that destroy blocks. */ - static void DamageBlocks(cChunk & a_Chunk, const Vector3f a_Position, const unsigned a_Power, const bool a_Fiery) + static void DamageBlocks(cChunk & a_Chunk, const Vector3f a_Position, const unsigned a_Power, const bool a_Fiery, const cEntity * const a_ExplodingEntity) { const auto Intensity = a_Power * (0.7f + GetRandomProvider().RandReal(0.6f)); const auto ExplosionRadius = CeilC((Intensity / StepAttenuation) * StepUnit); @@ -236,8 +236,8 @@ namespace Explodinator { for (int OffsetZ = -HalfSide; OffsetZ < HalfSide; OffsetZ++) { - DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(OffsetX, +ExplosionRadius, OffsetZ), a_Power, a_Fiery, Intensity); - DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(OffsetX, -ExplosionRadius, OffsetZ), a_Power, a_Fiery, Intensity); + DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(OffsetX, +ExplosionRadius, OffsetZ), a_Power, a_Fiery, Intensity, a_ExplodingEntity); + DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(OffsetX, -ExplosionRadius, OffsetZ), a_Power, a_Fiery, Intensity, a_ExplodingEntity); } } @@ -263,10 +263,10 @@ namespace Explodinator { for (int OffsetY = -HalfSide + 1; OffsetY < HalfSide - 1; OffsetY++) { - DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(ExplosionRadius, OffsetY, Offset + 1), a_Power, a_Fiery, Intensity); - DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(-ExplosionRadius, OffsetY, Offset), a_Power, a_Fiery, Intensity); - DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(Offset, OffsetY, ExplosionRadius), a_Power, a_Fiery, Intensity); - DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(Offset + 1, OffsetY, -ExplosionRadius), a_Power, a_Fiery, Intensity); + DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(ExplosionRadius, OffsetY, Offset + 1), a_Power, a_Fiery, Intensity, a_ExplodingEntity); + DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(-ExplosionRadius, OffsetY, Offset), a_Power, a_Fiery, Intensity, a_ExplodingEntity); + DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(Offset, OffsetY, ExplosionRadius), a_Power, a_Fiery, Intensity, a_ExplodingEntity); + DestructionTrace(&a_Chunk, a_Position, a_Position + Vector3f(Offset + 1, OffsetY, -ExplosionRadius), a_Power, a_Fiery, Intensity, a_ExplodingEntity); } } } @@ -280,13 +280,13 @@ namespace Explodinator } } - void Kaboom(cWorld & a_World, const Vector3f a_Position, const unsigned a_Power, const bool a_Fiery) + void Kaboom(cWorld & a_World, const Vector3f a_Position, const unsigned a_Power, const bool a_Fiery, const cEntity * const a_ExplodingEntity) { - a_World.DoWithChunkAt(a_Position.Floor(), [a_Position, a_Power, a_Fiery](cChunk & a_Chunk) + a_World.DoWithChunkAt(a_Position.Floor(), [a_Position, a_Power, a_Fiery, a_ExplodingEntity](cChunk & a_Chunk) { LagTheClient(a_Chunk, a_Position, a_Power); DamageEntities(a_Chunk, a_Position, a_Power); - DamageBlocks(a_Chunk, AbsoluteToRelative(a_Position, a_Chunk.GetPos()), a_Power, a_Fiery); + DamageBlocks(a_Chunk, AbsoluteToRelative(a_Position, a_Chunk.GetPos()), a_Power, a_Fiery, a_ExplodingEntity); return false; }); diff --git a/src/Physics/Explodinator.h b/src/Physics/Explodinator.h index daf86456a..4772618de 100644 --- a/src/Physics/Explodinator.h +++ b/src/Physics/Explodinator.h @@ -5,16 +5,17 @@ +class cEntity; class cWorld; - namespace Explodinator { /** Creates an explosion of Power, centred at Position, with ability to set fires as provided. For maximum efficiency, Position should be in the centre of the entity or block that exploded. + The entity pointer is used to trigger OnBreak for the destroyed blocks. Kaboom indeed, you drunken wretch. */ - void Kaboom(cWorld & World, Vector3f Position, unsigned Power, bool Fiery); + void Kaboom(cWorld & World, Vector3f Position, unsigned Power, bool Fiery, const cEntity * a_ExplodingEntity); } |