summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-09-02 21:56:55 +0200
committermadmaxoft <github@xoft.cz>2013-09-02 21:56:55 +0200
commite8b77ea2f5a9245f9ed3b28a7a637cf584037914 (patch)
treeba803ff23a825ce00593b750defc5e40dde12bbc
parentProjectiles don't collide with their creators. (diff)
downloadcuberite-e8b77ea2f5a9245f9ed3b28a7a637cf584037914.tar
cuberite-e8b77ea2f5a9245f9ed3b28a7a637cf584037914.tar.gz
cuberite-e8b77ea2f5a9245f9ed3b28a7a637cf584037914.tar.bz2
cuberite-e8b77ea2f5a9245f9ed3b28a7a637cf584037914.tar.lz
cuberite-e8b77ea2f5a9245f9ed3b28a7a637cf584037914.tar.xz
cuberite-e8b77ea2f5a9245f9ed3b28a7a637cf584037914.tar.zst
cuberite-e8b77ea2f5a9245f9ed3b28a7a637cf584037914.zip
-rw-r--r--source/Entities/ProjectileEntity.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/source/Entities/ProjectileEntity.cpp b/source/Entities/ProjectileEntity.cpp
index 8bc9abdb0..bef411559 100644
--- a/source/Entities/ProjectileEntity.cpp
+++ b/source/Entities/ProjectileEntity.cpp
@@ -24,13 +24,18 @@ class cProjectileTracerCallback :
{
public:
cProjectileTracerCallback(cProjectileEntity * a_Projectile) :
- m_Projectile(a_Projectile)
+ m_Projectile(a_Projectile),
+ m_SlowdownCoeff(0.99) // Default slowdown when not in water
{
}
+ double GetSlowdownCoeff(void) const { return m_SlowdownCoeff; }
+
protected:
cProjectileEntity * m_Projectile;
+ double m_SlowdownCoeff;
+ // cCallbacks overrides:
virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
{
if (g_BlockIsSolid[a_BlockType])
@@ -47,12 +52,14 @@ protected:
case E_BLOCK_STATIONARY_LAVA:
{
m_Projectile->StartBurning(30);
+ m_SlowdownCoeff = std::min(m_SlowdownCoeff, 0.9); // Slow down to 0.9* the speed each tick when moving through lava
break;
}
case E_BLOCK_WATER:
case E_BLOCK_STATIONARY_WATER:
{
m_Projectile->StopBurning();
+ m_SlowdownCoeff = std::min(m_SlowdownCoeff, 0.8); // Slow down to 0.8* the speed each tick when moving through water
break;
}
} // switch (a_BlockType)
@@ -280,6 +287,7 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
// Something has been hit, abort all other processing
return;
}
+ // The tracer also checks the blocks for slowdown blocks - water and lava - and stores it for later
// Test for entity collisions:
cProjectileEntityCollisionCallback EntityCollisionCallback(this, Pos, NextPos);
@@ -303,8 +311,11 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
// Update the position:
SetPosition(NextPos);
- // Add gravity effect to the vertical speed component:
- SetSpeedY(GetSpeedY() + m_Gravity / 20);
+ // Add slowdown and gravity effect to the speed:
+ Vector3d NewSpeed(GetSpeed());
+ NewSpeed.y += m_Gravity / 20;
+ NewSpeed *= TracerCallback.GetSlowdownCoeff();
+ SetSpeed(NewSpeed);
// DEBUG:
LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}",