From ec9787bae21f92251a38338ae5823aa851c5efea Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 24 Apr 2014 19:16:16 -0700 Subject: Chicken eggs and ender pearls can hit entities. Fixed warning by adding dedicated m_HasTeleported for fired arrows. --- src/Entities/ProjectileEntity.cpp | 62 +++++++++++++++++++++++++++++++++++---- src/Entities/ProjectileEntity.h | 11 ++++++- 2 files changed, 66 insertions(+), 7 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 96db17ffd..2725822f3 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -562,12 +562,12 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) // We can afford to do this because xoft's algorithm for trajectory is near perfect, so things are pretty close anyway without sync // Besides, this seems to be what the vanilla server does, note how arrows teleport half a second after they hit to the server position - if (m_HitGroundTimer != -1) // Sent a teleport already, don't do again + if (!m_HasTeleported) // Sent a teleport already, don't do again { if (m_HitGroundTimer > 1000.f) // Send after a second, could be less, but just in case { m_World->BroadcastTeleportEntity(*this); - m_HitGroundTimer = -1; + m_HasTeleported = true; } else { @@ -610,6 +610,32 @@ cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + TryForChicken(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TryForChicken(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEggEntity::TryForChicken(const Vector3d & a_HitPos) { if (m_World->GetTickRandomNumber(7) == 1) { @@ -622,7 +648,6 @@ void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_H m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); } - Destroy(); } @@ -643,16 +668,40 @@ cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // TODO: Tweak a_HitPos based on block face. + TeleportUser(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TeleportUser(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEnderPearlEntity::TeleportUser(const Vector3d & a_HitPos) { // Teleport the creator here, make them take 5 damage: if (m_Creator != NULL) { - // TODO: The coords might need some tweaking based on the block face m_Creator->TeleportToCoords(a_HitPos.x + 0.5, a_HitPos.y + 1.7, a_HitPos.z + 0.5); m_Creator->TakeDamage(dtEnderPearl, this, 5, 0); } - - Destroy(); } @@ -696,6 +745,7 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & TotalDamage = 1; } } + // TODO: If entity is Ender Crystal, destroy it a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index efb7ae783..002aa09a1 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -166,6 +166,9 @@ protected: /// Timer for client arrow position confirmation via TeleportEntity float m_HitGroundTimer; + + // Whether the arrow has already been teleported into the proper position in the ground. + bool m_HasTeleported; /// If true, the arrow is in the process of being collected - don't go to anyone else bool m_bIsCollected; @@ -205,7 +208,10 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + void TryForChicken(const Vector3d & a_HitPos); + // tolua_begin } ; @@ -233,6 +239,9 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + void TeleportUser(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From cb7f1ee4bbf726b5b57fe8d1960bb7d03dc1e87a Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 05:39:35 -0700 Subject: Rename spawn chicken method, Initialize m_HasTeleported. --- src/Entities/ProjectileEntity.cpp | 7 ++++--- src/Entities/ProjectileEntity.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 2725822f3..89b833abf 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -440,6 +440,7 @@ cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : m_IsCritical((a_Force >= 1)), m_Timer(0), m_HitGroundTimer(0), + m_HasTeleported(false), m_bIsCollected(false), m_HitBlockPos(0, 0, 0) { @@ -611,7 +612,7 @@ cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { - TryForChicken(a_HitPos); + TrySpawnChicken(a_HitPos); Destroy(); } @@ -625,7 +626,7 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit int TotalDamage = 0; // TODO: If entity is Ender Crystal, destroy it - TryForChicken(a_HitPos); + TrySpawnChicken(a_HitPos); a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); @@ -635,7 +636,7 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit -void cThrownEggEntity::TryForChicken(const Vector3d & a_HitPos) +void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) { if (m_World->GetTickRandomNumber(7) == 1) { diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 002aa09a1..90d44ed91 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -210,7 +210,7 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - void TryForChicken(const Vector3d & a_HitPos); + void TrySpawnChicken(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From 256691461bd9c4719e94d17942372ef8302a3607 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 05:49:18 -0700 Subject: Comments for TrySpawnChicken() and TeleportUser(). --- src/Entities/ProjectileEntity.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 90d44ed91..5aa489ff8 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -210,6 +210,7 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + // Randomly decides whether to spawn a chicken where the egg lands. void TrySpawnChicken(const Vector3d & a_HitPos); // tolua_begin @@ -241,6 +242,7 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + // Teleports the user where the ender pearl lands. void TeleportUser(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From 8aa82d048d4506c963846d5c02650e1037e92992 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 06:26:08 -0700 Subject: Creator not user. --- src/Entities/ProjectileEntity.cpp | 6 +++--- src/Entities/ProjectileEntity.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 89b833abf..fd3e80e5f 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -671,7 +671,7 @@ cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { // TODO: Tweak a_HitPos based on block face. - TeleportUser(a_HitPos); + TeleportCreator(a_HitPos); Destroy(); } @@ -685,7 +685,7 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d int TotalDamage = 0; // TODO: If entity is Ender Crystal, destroy it - TeleportUser(a_HitPos); + TeleportCreator(a_HitPos); a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); @@ -695,7 +695,7 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d -void cThrownEnderPearlEntity::TeleportUser(const Vector3d & a_HitPos) +void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) { // Teleport the creator here, make them take 5 damage: if (m_Creator != NULL) diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 5aa489ff8..731dd060e 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -242,8 +242,8 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - // Teleports the user where the ender pearl lands. - void TeleportUser(const Vector3d & a_HitPos); + // Teleports the creator where the ender pearl lands. + void TeleportCreator(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3