From 7e76f030aa2e6d39ac7fe9fb6a8a3db44bf3dd5f Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 00:32:30 +0200 Subject: Add entity invulnerable --- src/Entities/Boat.cpp | 8 ++++++-- src/Entities/Boat.h | 2 +- src/Entities/Entity.cpp | 21 ++++++++++++++++++--- src/Entities/Entity.h | 17 +++++++++++++---- src/Entities/Minecart.cpp | 14 +++++++++----- src/Entities/Minecart.h | 2 +- src/Entities/Player.cpp | 21 ++++++++++++--------- src/Entities/Player.h | 2 +- 8 files changed, 61 insertions(+), 26 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 921252253..31bfe3dc3 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -33,9 +33,12 @@ void cBoat::SpawnOn(cClientHandle & a_ClientHandle) -void cBoat::DoTakeDamage(TakeDamageInfo & TDI) +bool cBoat::DoTakeDamage(TakeDamageInfo & TDI) { - super::DoTakeDamage(TDI); + if (!super::DoTakeDamage(TDI)) + { + return false; + } if (GetHealth() == 0) { @@ -50,6 +53,7 @@ void cBoat::DoTakeDamage(TakeDamageInfo & TDI) } Destroy(true); } + return true; } diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h index c4c9afe7a..0fcfbd602 100644 --- a/src/Entities/Boat.h +++ b/src/Entities/Boat.h @@ -26,7 +26,7 @@ public: // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void OnRightClicked(cPlayer & a_Player) override; - virtual void DoTakeDamage(TakeDamageInfo & TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & TDI) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override; diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 6da6da54e..4403ab161 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -60,6 +60,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_Mass (0.001) // Default 1g , m_Width(a_Width) , m_Height(a_Height) + , m_InvulnerableTicks(20) { cCSLock Lock(m_CSCount); m_EntityCount++; @@ -294,17 +295,23 @@ void cEntity::SetPitchFromSpeed(void) -void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) { if (cRoot::Get()->GetPluginManager()->CallHookTakeDamage(*this, a_TDI)) { - return; + return false; } if (m_Health <= 0) { // Can't take damage if already dead - return; + return false; + } + + if (m_InvulnerableTicks > 0) + { + // Entity is invulnerable + return false; } if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) @@ -333,10 +340,13 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_World->BroadcastEntityStatus(*this, esGenericHurt); + m_InvulnerableTicks = 10; + if (m_Health <= 0) { KilledBy(a_TDI.Attacker); } + return true; } @@ -511,6 +521,11 @@ void cEntity::SetHealth(int a_Health) void cEntity::Tick(float a_Dt, cChunk & a_Chunk) { + if (m_InvulnerableTicks > 0) + { + m_InvulnerableTicks--; + } + if (m_AttachedTo != NULL) { if ((m_Pos - m_AttachedTo->GetPosition()).Length() > 0.5) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 86efc5a98..fc4186afc 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -262,8 +262,8 @@ public: // tolua_end - /// Makes this entity take damage specified in the a_TDI. The TDI is sent through plugins first, then applied - virtual void DoTakeDamage(TakeDamageInfo & a_TDI); + /** Makes this entity take damage specified in the a_TDI. The TDI is sent through plugins first, then applied. If it returns false, the entity hasn't become any damage. */ + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI); // tolua_begin @@ -391,6 +391,12 @@ public: virtual bool IsSubmerged(void) const{ return m_IsSubmerged; } /** Gets remaining air of a monster */ int GetAirLevel(void) const { return m_AirLevel; } + + /** Gets the invulnerable ticks from the entity */ + int GetInvulnerableTicks(void) const { return m_InvulnerableTicks; } + + /** Set the invulnerable ticks from the entity */ + void SetInvulnerableTicks(int a_InvulnerableTicks) { m_InvulnerableTicks = a_InvulnerableTicks; } // tolua_end @@ -493,11 +499,14 @@ private: // Measured in Kilograms (Kg) double m_Mass; - /// Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. + // Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. double m_Width; - /// Height of the entity (Y axis) + // Height of the entity (Y axis) double m_Height; + + // If a player hunt a entity, the entity become a invulnerable of 20 ticks + int m_InvulnerableTicks; } ; // tolua_export typedef std::list cEntityList; diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index db55eb058..7bd440d6d 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -902,18 +902,21 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) -void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) +bool cMinecart::DoTakeDamage(TakeDamageInfo & TDI) { if ((TDI.Attacker != NULL) && TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) { Destroy(); TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative - super::DoTakeDamage(TDI); - return; // No drops for creative + SetInvulnerableTicks(0); + return super::DoTakeDamage(TDI); // No drops for creative } m_LastDamage = TDI.FinalDamage; - super::DoTakeDamage(TDI); + if (!super::DoTakeDamage(TDI)) + { + return false; + } m_World->BroadcastEntityMetadata(*this); @@ -952,12 +955,13 @@ void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) default: { ASSERT(!"Unhandled minecart type when spawning pickup!"); - return; + return true; } } m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ()); } + return true; } diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index ebdb576e0..1e60f091c 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -36,7 +36,7 @@ public: // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; - virtual void DoTakeDamage(TakeDamageInfo & TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & TDI) override; virtual void Destroyed() override; int LastDamage(void) const { return m_LastDamage; } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index fedb62527..08b7d3984 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -808,14 +808,14 @@ void cPlayer::SetFlying(bool a_IsFlying) -void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) +bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtPlugin)) { if (IsGameModeCreative()) { // No damage / health in creative mode if not void or plugin damage - return; + return false; } } @@ -828,17 +828,19 @@ void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) if (!m_Team->AllowsFriendlyFire()) { // Friendly fire is disabled - return; + return false; } } } - super::DoTakeDamage(a_TDI); - - // Any kind of damage adds food exhaustion - AddFoodExhaustion(0.3f); - - SendHealth(); + if (super::DoTakeDamage(a_TDI)) + { + // Any kind of damage adds food exhaustion + AddFoodExhaustion(0.3f); + SendHealth(); + return true; + } + return false; } @@ -897,6 +899,7 @@ void cPlayer::KilledBy(cEntity * a_Killer) void cPlayer::Respawn(void) { m_Health = GetMaxHealth(); + SetInvulnerableTicks(20); // Reset food level: m_FoodLevel = MAX_FOOD_LEVEL; diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 78d661015..3029abfe0 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -498,7 +498,7 @@ protected: virtual void Destroyed(void); /** Filters out damage for creative mode/friendly fire */ - virtual void DoTakeDamage(TakeDamageInfo & TDI) override; + virtual bool DoTakeDamage(TakeDamageInfo & TDI) override; /** Stops players from burning in creative mode */ virtual void TickBurning(cChunk & a_Chunk) override; -- cgit v1.2.3 From ad1410f46e5deccc9f9a38e360fa65d6e33b82b4 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 00:37:09 +0200 Subject: Change m_InvulnerableTicks description --- src/Entities/Entity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index fc4186afc..ac9cf8b32 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -505,7 +505,7 @@ private: // Height of the entity (Y axis) double m_Height; - // If a player hunt a entity, the entity become a invulnerable of 20 ticks + // If a player hit a entity, the entity become a invulnerable of 20 ticks int m_InvulnerableTicks; } ; // tolua_export -- cgit v1.2.3 From ed1aa02d0c0efbffbaf46c8f17dc4c52c9e6f34d Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 00:37:40 +0200 Subject: Change m_InvulnerableTicks description again. --- src/Entities/Entity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index ac9cf8b32..ba74a38a9 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -505,7 +505,7 @@ private: // Height of the entity (Y axis) double m_Height; - // If a player hit a entity, the entity become a invulnerable of 20 ticks + // If a player hit a entity, the entity become a invulnerable of 10 ticks int m_InvulnerableTicks; } ; // tolua_export -- cgit v1.2.3 From e5683ede63572fe8b40703d449adf784b7d80ea7 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 00:41:00 +0200 Subject: Change m_InvulnerableTicks description again again :D --- src/Entities/Entity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index ba74a38a9..e76279c28 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -505,7 +505,7 @@ private: // Height of the entity (Y axis) double m_Height; - // If a player hit a entity, the entity become a invulnerable of 10 ticks + // If a player hit a entity, the entity become a invulnerable of 10 ticks. While this ticks, a player can't hit this entity. int m_InvulnerableTicks; } ; // tolua_export -- cgit v1.2.3 From 73edd2b96102bff9fbd74d34740fea3daa40b15f Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 17:15:12 -0700 Subject: Fixed a couple more warnings. --- src/Entities/FallingBlock.cpp | 4 +++- src/Entities/Minecart.cpp | 34 ++++++++++++++-------------------- 2 files changed, 17 insertions(+), 21 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index a66c7e4ae..f48fb156b 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -87,7 +87,9 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) AddSpeedY(MilliDt * -9.8f); AddPosition(GetSpeed() * MilliDt); - if ((GetSpeedX() != 0) || (GetSpeedZ() != 0)) + //If not static (One billionth precision) broadcast movement. + float epsilon = 0.000000001; + if ((fabs(GetSpeedX()) > epsilon) || (fabs(GetSpeedZ()) > epsilon)) { BroadcastMovementUpdate(); } diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index db55eb058..ceaa713bb 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -234,18 +234,15 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedZ() != 0) // Don't do anything if cart is stationary + if (GetSpeedZ() > 0) { - if (GetSpeedZ() > 0) - { - // Going SOUTH, slow down - AddSpeedZ(-0.1); - } - else - { - // Going NORTH, slow down - AddSpeedZ(0.1); - } + // Going SOUTH, slow down + AddSpeedZ(-0.1); + } + else if (GetSpeedZ() < 0) + { + // Going NORTH, slow down + AddSpeedZ(0.1); } break; } @@ -259,16 +256,13 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedX() != 0) + if (GetSpeedX() > 0) { - if (GetSpeedX() > 0) - { - AddSpeedX(-0.1); - } - else - { - AddSpeedX(0.1); - } + AddSpeedX(-0.1); + } + else if (GetSpeedX() < 0) + { + AddSpeedX(0.1); } break; } -- cgit v1.2.3 From acff6148b61a64b3d8bec791ca936457fc61a096 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 19:49:08 -0700 Subject: Moved switch{} out of GetArmorCoverAgainst(). --- src/Entities/Entity.cpp | 31 ++++++++++++++++++++++++++----- src/Entities/Entity.h | 3 +++ 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 6da6da54e..49e7e45e2 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -381,11 +381,8 @@ int cEntity::GetRawDamageAgainst(const cEntity & a_Receiver) -int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage) +bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) { - // Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover - - // Filter out damage types that are not protected by armor: // Ref.: http://www.minecraftwiki.net/wiki/Armor#Effects as of 2012_12_20 switch (a_DamageType) { @@ -400,9 +397,33 @@ int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_Dama case dtLightning: case dtPlugin: { - return 0; + return false; + } + + case dtAttack: + case dtArrowAttack: + case dtCactusContact: + case dtLavaContact: + case dtFireContact: + case dtEnderPearl: + case dtExplosion: + { + return true; } } + ASSERT("Invalid damage type!"); +} + + + + + +int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage) +{ + // Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover + + // Filter out damage types that are not protected by armor: + if (!ArmorCoversAgainst(a_DamageType)) return 0; // Add up all armor points: // Ref.: http://www.minecraftwiki.net/wiki/Armor#Defense_points as of 2012_12_20 diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 86efc5a98..db40f12ed 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -270,6 +270,9 @@ public: /// Returns the hitpoints that this pawn can deal to a_Receiver using its equipped items virtual int GetRawDamageAgainst(const cEntity & a_Receiver); + // Returns whether armor will protect against the passed damage type + virtual bool ArmorCoversAgainst(eDamageType a_DamageType); + /// Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover virtual int GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_RawDamage); -- cgit v1.2.3 From 49f6819829b437f776ea08f50c92cc506ee9ddcb Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Apr 2014 16:44:15 +0200 Subject: Fixes --- src/Entities/Entity.cpp | 2 +- src/Entities/Entity.h | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 0af4eafde..db657909c 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -60,7 +60,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_Mass (0.001) // Default 1g , m_Width(a_Width) , m_Height(a_Height) - , m_InvulnerableTicks(20) + , m_InvulnerableTicks(0) { cCSLock Lock(m_CSCount); m_EntityCount++; diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index e76279c28..26edf8dca 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -262,7 +262,9 @@ public: // tolua_end - /** Makes this entity take damage specified in the a_TDI. The TDI is sent through plugins first, then applied. If it returns false, the entity hasn't become any damage. */ + /** Makes this entity take damage specified in the a_TDI. + The TDI is sent through plugins first, then applied. + If it returns false, the entity hasn't receive any damage. */ virtual bool DoTakeDamage(TakeDamageInfo & a_TDI); // tolua_begin @@ -481,31 +483,32 @@ protected: int m_AirTickTimer; private: - // Measured in degrees, [-180, +180) + /** Measured in degrees, [-180, +180) */ double m_HeadYaw; - // Measured in meter/second (m/s) + /** Measured in meter/second (m/s) */ Vector3d m_Speed; - // Measured in degrees, [-180, +180) + /** Measured in degrees, [-180, +180) */ Vector3d m_Rot; - /// Position of the entity's XZ center and Y bottom + /** Position of the entity's XZ center and Y bottom */ Vector3d m_Pos; - // Measured in meter / second + /** Measured in meter / second */ Vector3d m_WaterSpeed; - // Measured in Kilograms (Kg) + /** Measured in Kilograms (Kg) */ double m_Mass; - // Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. + /** Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. */ double m_Width; - // Height of the entity (Y axis) + /** Height of the entity (Y axis) */ double m_Height; - // If a player hit a entity, the entity become a invulnerable of 10 ticks. While this ticks, a player can't hit this entity. + /** If a player hit a entity, the entity receive a invulnerable of 10 ticks. + While this ticks, a player can't hit this entity. */ int m_InvulnerableTicks; } ; // tolua_export -- cgit v1.2.3 From aef2c8ec628aa2522364da1333bc5158e55ac6a2 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 09:21:49 -0700 Subject: Further refactored, Reverted Minecart change Other small changes. --- src/Entities/Entity.cpp | 2 +- src/Entities/Entity.h | 2 +- src/Entities/FallingBlock.cpp | 2 +- src/Entities/Minecart.cpp | 34 ++++++++++++++++++++-------------- 4 files changed, 23 insertions(+), 17 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 49e7e45e2..961caf493 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -411,7 +411,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) return true; } } - ASSERT("Invalid damage type!"); + ASSERT(!"Invalid damage type!"); } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index db40f12ed..9b8011b55 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -270,7 +270,7 @@ public: /// Returns the hitpoints that this pawn can deal to a_Receiver using its equipped items virtual int GetRawDamageAgainst(const cEntity & a_Receiver); - // Returns whether armor will protect against the passed damage type + /** Returns whether armor will protect against the passed damage type **/ virtual bool ArmorCoversAgainst(eDamageType a_DamageType); /// Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index f48fb156b..50140de67 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -88,7 +88,7 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) AddPosition(GetSpeed() * MilliDt); //If not static (One billionth precision) broadcast movement. - float epsilon = 0.000000001; + static const float epsilon = 0.000000001; if ((fabs(GetSpeedX()) > epsilon) || (fabs(GetSpeedZ()) > epsilon)) { BroadcastMovementUpdate(); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index ceaa713bb..db55eb058 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -234,15 +234,18 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedZ() > 0) - { - // Going SOUTH, slow down - AddSpeedZ(-0.1); - } - else if (GetSpeedZ() < 0) + if (GetSpeedZ() != 0) // Don't do anything if cart is stationary { - // Going NORTH, slow down - AddSpeedZ(0.1); + if (GetSpeedZ() > 0) + { + // Going SOUTH, slow down + AddSpeedZ(-0.1); + } + else + { + // Going NORTH, slow down + AddSpeedZ(0.1); + } } break; } @@ -256,13 +259,16 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedX() > 0) - { - AddSpeedX(-0.1); - } - else if (GetSpeedX() < 0) + if (GetSpeedX() != 0) { - AddSpeedX(0.1); + if (GetSpeedX() > 0) + { + AddSpeedX(-0.1); + } + else + { + AddSpeedX(0.1); + } } break; } -- cgit v1.2.3 From 7841bad27ad97736ddf21b86e2409f20c6392e69 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 14:01:48 -0700 Subject: More small fixes. --- src/Entities/FallingBlock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index 50140de67..bcdac0291 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -87,7 +87,7 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) AddSpeedY(MilliDt * -9.8f); AddPosition(GetSpeed() * MilliDt); - //If not static (One billionth precision) broadcast movement. + // If not static (One billionth precision) broadcast movement. static const float epsilon = 0.000000001; if ((fabs(GetSpeedX()) > epsilon) || (fabs(GetSpeedZ()) > epsilon)) { -- cgit v1.2.3 From e2194e6e9083b54914deac3a5a6c2e3e4d262990 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 15:32:14 -0700 Subject: Added static const, initialized fields. --- src/Entities/Entity.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 7c8e18b51..827b88717 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -53,6 +53,8 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_TicksSinceLastVoidDamage(0) , m_IsSwimming(false) , m_IsSubmerged(false) + , m_AirLevel(0) + , m_AirTickTimer(0) , m_HeadYaw( 0.0 ) , m_Rot(0.0, 0.0, 0.0) , m_Pos(a_X, a_Y, a_Z) -- cgit v1.2.3 From 477b3e7861ca03aec5c46b4c192f5cc1b5f07c4d Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 16:45:39 -0700 Subject: Moved cArrowEntity out of ProjectileEntity.h --- src/Entities/ProjectileArrow.cpp | 193 +++++++++++++++++++++++++++++++++++++ src/Entities/ProjectileArrow.h | 95 +++++++++++++++++++ src/Entities/ProjectileEntity.cpp | 195 +------------------------------------- src/Entities/ProjectileEntity.h | 88 ----------------- 4 files changed, 291 insertions(+), 280 deletions(-) create mode 100644 src/Entities/ProjectileArrow.cpp create mode 100644 src/Entities/ProjectileArrow.h (limited to 'src/Entities') diff --git a/src/Entities/ProjectileArrow.cpp b/src/Entities/ProjectileArrow.cpp new file mode 100644 index 000000000..bd4f2abab --- /dev/null +++ b/src/Entities/ProjectileArrow.cpp @@ -0,0 +1,193 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Player.h" +#include "ProjectileArrow.h" +#include "../Chunk.h" + + + + + +cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5), +m_PickupState(psNoPickup), +m_DamageCoeff(2), +m_IsCritical(false), +m_Timer(0), +m_HitGroundTimer(0), +m_bIsCollected(false), +m_HitBlockPos(Vector3i(0, 0, 0)) +{ + SetSpeed(a_Speed); + SetMass(0.1); + SetYawFromSpeed(); + SetPitchFromSpeed(); + LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", + m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), + GetYaw(), GetPitch() + ); +} + + + + + +cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : +super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), +m_PickupState(psInSurvivalOrCreative), +m_DamageCoeff(2), +m_IsCritical((a_Force >= 1)), +m_Timer(0), +m_HitGroundTimer(0), +m_HasTeleported(false), +m_bIsCollected(false), +m_HitBlockPos(0, 0, 0) +{ +} + + + + + +bool cArrowEntity::CanPickup(const cPlayer & a_Player) const +{ + switch (m_PickupState) + { + case psNoPickup: return false; + case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); + case psInCreative: return a_Player.IsGameModeCreative(); + } + ASSERT(!"Unhandled pickup state"); + return false; +} + + + + + +void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + if (a_HitFace == BLOCK_FACE_NONE) { return; } + + super::OnHitSolidBlock(a_HitPos, a_HitFace); + int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z; + + switch (a_HitFace) + { + case BLOCK_FACE_XM: // Strangely, bounding boxes / block tracers return the actual block for these two directions, so AddFace not needed + case BLOCK_FACE_YM: + { + break; + } + default: AddFaceDirection(a_X, a_Y, a_Z, a_HitFace, true); + } + + m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); + + // Broadcast arrow hit sound + m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); +} + + + + + +void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat()) + { + // Not an entity that interacts with an arrow + return; + } + + int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); + if (m_IsCritical) + { + Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); + } + a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); + + // Broadcast successful hit sound + m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + + Destroy(); +} + + + + + +void cArrowEntity::CollectedBy(cPlayer * a_Dest) +{ + if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) + { + int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); + if (NumAdded > 0) // Only play effects if there was space in inventory + { + m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); + // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) + m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_bIsCollected = true; + } + } +} + + + + + +void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + m_Timer += a_Dt; + + if (m_bIsCollected) + { + if (m_Timer > 500.f) // 0.5 seconds + { + Destroy(); + return; + } + } + else if (m_Timer > 1000 * 60 * 5) // 5 minutes + { + Destroy(); + return; + } + + if (m_IsInGround) + { + // When an arrow hits, the client doesn't think its in the ground and keeps on moving, IF BroadcastMovementUpdate() and TeleportEntity was called during flight, AT ALL + // Fix is to simply not sync with the client and send a teleport to confirm pos after arrow has stabilised (around 1 sec after landing) + // 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_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_HasTeleported = true; + } + else + { + m_HitGroundTimer += a_Dt; + } + } + + int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; + int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; + cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); + + if (Chunk == NULL) + { + // Inside an unloaded chunk, abort + return; + } + + if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? + { + m_IsInGround = false; // Yes, begin simulating physics again + } + } +} \ No newline at end of file diff --git a/src/Entities/ProjectileArrow.h b/src/Entities/ProjectileArrow.h new file mode 100644 index 000000000..c08b7acc5 --- /dev/null +++ b/src/Entities/ProjectileArrow.h @@ -0,0 +1,95 @@ +// +// ProjectileArrow.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cArrowEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field + enum ePickupState + { + psNoPickup = 0, + psInSurvivalOrCreative = 1, + psInCreative = 2, + } ; + + // tolua_end + + CLASS_PROTODEF(cArrowEntity); + + /// Creates a new arrow with psNoPickup state and default damage modifier coeff + cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + + /// Creates a new arrow as shot by a player, initializes it from the player object + cArrowEntity(cPlayer & a_Player, double a_Force); + + // tolua_begin + + /// Returns whether the arrow can be picked up by players + ePickupState GetPickupState(void) const { return m_PickupState; } + + /// Sets a new pickup state + void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; } + + /// Returns the damage modifier coeff. + double GetDamageCoeff(void) const { return m_DamageCoeff; } + + /// Sets the damage modifier coeff + void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; } + + /// Returns true if the specified player can pick the arrow up + bool CanPickup(const cPlayer & a_Player) const; + + /// Returns true if the arrow is set as critical + bool IsCritical(void) const { return m_IsCritical; } + + /// Sets the IsCritical flag + void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; } + + // tolua_end + +protected: + + /// Determines when the arrow can be picked up by players + ePickupState m_PickupState; + + /// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow + double m_DamageCoeff; + + /// If true, the arrow deals more damage + bool m_IsCritical; + + /// Timer for pickup collection animation or five minute timeout + float m_Timer; + + /// 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; + + /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air + Vector3i m_HitBlockPos; + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + virtual void CollectedBy(cPlayer * a_Player) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + + // tolua_begin +}; \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index fd3e80e5f..079adcc5f 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -4,15 +4,17 @@ // Implements the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types #include "Globals.h" + #include "../Bindings/PluginManager.h" #include "ProjectileEntity.h" #include "../ClientHandle.h" -#include "Player.h" #include "../LineBlockTracer.h" #include "../BoundingBox.h" #include "../ChunkMap.h" #include "../Chunk.h" +#include "ProjectileArrow.h" + @@ -406,197 +408,6 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cArrowEntity: - -cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5), - m_PickupState(psNoPickup), - m_DamageCoeff(2), - m_IsCritical(false), - m_Timer(0), - m_HitGroundTimer(0), - m_bIsCollected(false), - m_HitBlockPos(Vector3i(0, 0, 0)) -{ - SetSpeed(a_Speed); - SetMass(0.1); - SetYawFromSpeed(); - SetPitchFromSpeed(); - LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", - m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), - GetYaw(), GetPitch() - ); -} - - - - - -cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : - super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), - m_PickupState(psInSurvivalOrCreative), - m_DamageCoeff(2), - m_IsCritical((a_Force >= 1)), - m_Timer(0), - m_HitGroundTimer(0), - m_HasTeleported(false), - m_bIsCollected(false), - m_HitBlockPos(0, 0, 0) -{ -} - - - - - -bool cArrowEntity::CanPickup(const cPlayer & a_Player) const -{ - switch (m_PickupState) - { - case psNoPickup: return false; - case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); - case psInCreative: return a_Player.IsGameModeCreative(); - } - ASSERT(!"Unhandled pickup state"); - return false; -} - - - - - -void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - if (a_HitFace == BLOCK_FACE_NONE) { return; } - - super::OnHitSolidBlock(a_HitPos, a_HitFace); - int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z; - - switch (a_HitFace) - { - case BLOCK_FACE_XM: // Strangely, bounding boxes / block tracers return the actual block for these two directions, so AddFace not needed - case BLOCK_FACE_YM: - { - break; - } - default: AddFaceDirection(a_X, a_Y, a_Z, a_HitFace, true); - } - - m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); - - // Broadcast arrow hit sound - m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); -} - - - - - -void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat()) - { - // Not an entity that interacts with an arrow - return; - } - - int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); - if (m_IsCritical) - { - Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); - } - a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); - - // Broadcast successful hit sound - m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - - Destroy(); -} - - - - - -void cArrowEntity::CollectedBy(cPlayer * a_Dest) -{ - if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) - { - int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); - if (NumAdded > 0) // Only play effects if there was space in inventory - { - m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); - // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) - m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - m_bIsCollected = true; - } - } -} - - - - - -void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - m_Timer += a_Dt; - - if (m_bIsCollected) - { - if (m_Timer > 500.f) // 0.5 seconds - { - Destroy(); - return; - } - } - else if (m_Timer > 1000 * 60 * 5) // 5 minutes - { - Destroy(); - return; - } - - if (m_IsInGround) - { - // When an arrow hits, the client doesn't think its in the ground and keeps on moving, IF BroadcastMovementUpdate() and TeleportEntity was called during flight, AT ALL - // Fix is to simply not sync with the client and send a teleport to confirm pos after arrow has stabilised (around 1 sec after landing) - // 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_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_HasTeleported = true; - } - else - { - m_HitGroundTimer += a_Dt; - } - } - - int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; - int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; - cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); - - if (Chunk == NULL) - { - // Inside an unloaded chunk, abort - return; - } - - if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? - { - m_IsInGround = false; // Yes, begin simulating physics again - } - } -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cThrownEggEntity: diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 731dd060e..2b2ed634c 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -101,94 +101,6 @@ protected: -class cArrowEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field - enum ePickupState - { - psNoPickup = 0, - psInSurvivalOrCreative = 1, - psInCreative = 2, - } ; - - // tolua_end - - CLASS_PROTODEF(cArrowEntity); - - /// Creates a new arrow with psNoPickup state and default damage modifier coeff - cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - - /// Creates a new arrow as shot by a player, initializes it from the player object - cArrowEntity(cPlayer & a_Player, double a_Force); - - // tolua_begin - - /// Returns whether the arrow can be picked up by players - ePickupState GetPickupState(void) const { return m_PickupState; } - - /// Sets a new pickup state - void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; } - - /// Returns the damage modifier coeff. - double GetDamageCoeff(void) const { return m_DamageCoeff; } - - /// Sets the damage modifier coeff - void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; } - - /// Returns true if the specified player can pick the arrow up - bool CanPickup(const cPlayer & a_Player) const; - - /// Returns true if the arrow is set as critical - bool IsCritical(void) const { return m_IsCritical; } - - /// Sets the IsCritical flag - void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; } - - // tolua_end - -protected: - - /// Determines when the arrow can be picked up by players - ePickupState m_PickupState; - - /// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow - double m_DamageCoeff; - - /// If true, the arrow deals more damage - bool m_IsCritical; - - /// Timer for pickup collection animation or five minute timeout - float m_Timer; - - /// 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; - - /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air - Vector3i m_HitBlockPos; - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void CollectedBy(cPlayer * a_Player) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - - // tolua_begin -} ; - - - - - class cThrownEggEntity : public cProjectileEntity { -- cgit v1.2.3 From de23a115a5a33a864111262f4dae08b524af422f Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:02:47 -0700 Subject: Moved cThrownEggEntity out of ProjectileEntity.h --- src/Entities/ProjectileEgg.cpp | 59 +++++++++++++++++++++++++++++++++++++++ src/Entities/ProjectileEgg.h | 39 ++++++++++++++++++++++++++ src/Entities/ProjectileEntity.cpp | 59 +-------------------------------------- src/Entities/ProjectileEntity.h | 32 --------------------- 4 files changed, 99 insertions(+), 90 deletions(-) create mode 100644 src/Entities/ProjectileEgg.cpp create mode 100644 src/Entities/ProjectileEgg.h (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEgg.cpp b/src/Entities/ProjectileEgg.cpp new file mode 100644 index 000000000..61d61e1c6 --- /dev/null +++ b/src/Entities/ProjectileEgg.cpp @@ -0,0 +1,59 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileEgg.h" +#include "../World.h" + + + + + +cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkEgg, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + TrySpawnChicken(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TrySpawnChicken(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) +{ + if (m_World->GetTickRandomNumber(7) == 1) + { + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + } + else if (m_World->GetTickRandomNumber(32) == 1) + { + 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); + 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); + } +} \ No newline at end of file diff --git a/src/Entities/ProjectileEgg.h b/src/Entities/ProjectileEgg.h new file mode 100644 index 000000000..464526dfc --- /dev/null +++ b/src/Entities/ProjectileEgg.h @@ -0,0 +1,39 @@ +// +// ProjectileEgg.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cThrownEggEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownEggEntity); + + cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // tolua_end + + // cProjectileEntity overrides: + 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 + +} ; \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 079adcc5f..b4c162e35 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -14,6 +14,7 @@ #include "../Chunk.h" #include "ProjectileArrow.h" +#include "ProjectileEgg.h" @@ -408,64 +409,6 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cThrownEggEntity: - -cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkEgg, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - TrySpawnChicken(a_HitPos); - - Destroy(); -} - - - - - -void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - // TODO: If entity is Ender Crystal, destroy it - - TrySpawnChicken(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - -void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) -{ - if (m_World->GetTickRandomNumber(7) == 1) - { - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - } - else if (m_World->GetTickRandomNumber(32) == 1) - { - 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); - 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); - } -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cThrownEnderPearlEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 2b2ed634c..74f72c5d1 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -101,38 +101,6 @@ protected: -class cThrownEggEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownEggEntity); - - cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // tolua_end - - // cProjectileEntity overrides: - 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 - -} ; - - - - - class cThrownEnderPearlEntity : public cProjectileEntity { -- cgit v1.2.3 From bc5c28a0beef335edf3b930e069b9152ef0a912f Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:08:39 -0700 Subject: Moved cThrownEnderPearl out of ProjectileEntity.h --- src/Entities/ProjectileEnderPearl.cpp | 54 ++++++++++++++++++++++++++++++++++ src/Entities/ProjectileEnderPearl.h | 39 +++++++++++++++++++++++++ src/Entities/ProjectileEntity.cpp | 55 +---------------------------------- src/Entities/ProjectileEntity.h | 32 -------------------- 4 files changed, 94 insertions(+), 86 deletions(-) create mode 100644 src/Entities/ProjectileEnderPearl.cpp create mode 100644 src/Entities/ProjectileEnderPearl.h (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEnderPearl.cpp b/src/Entities/ProjectileEnderPearl.cpp new file mode 100644 index 000000000..4e848f189 --- /dev/null +++ b/src/Entities/ProjectileEnderPearl.cpp @@ -0,0 +1,54 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileEnderPearl.h" + + + + + +cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkEnderPearl, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // TODO: Tweak a_HitPos based on block face. + TeleportCreator(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TeleportCreator(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) +{ + // Teleport the creator here, make them take 5 damage: + if (m_Creator != NULL) + { + 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); + } +} \ No newline at end of file diff --git a/src/Entities/ProjectileEnderPearl.h b/src/Entities/ProjectileEnderPearl.h new file mode 100644 index 000000000..d6d052428 --- /dev/null +++ b/src/Entities/ProjectileEnderPearl.h @@ -0,0 +1,39 @@ +// +// ProjectileEnderPearl.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cThrownEnderPearlEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownEnderPearlEntity); + + cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // tolua_end + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // Teleports the creator where the ender pearl lands. + void TeleportCreator(const Vector3d & a_HitPos); + + // tolua_begin + +} ; \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index b4c162e35..d7e1f56a7 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -15,6 +15,7 @@ #include "ProjectileArrow.h" #include "ProjectileEgg.h" +#include "ProjectileEnderPearl.h" @@ -409,60 +410,6 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cThrownEnderPearlEntity : - -cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkEnderPearl, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - // TODO: Tweak a_HitPos based on block face. - TeleportCreator(a_HitPos); - - Destroy(); -} - - - - - -void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - // TODO: If entity is Ender Crystal, destroy it - - TeleportCreator(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - -void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) -{ - // Teleport the creator here, make them take 5 damage: - if (m_Creator != NULL) - { - 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); - } -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cThrownSnowballEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 74f72c5d1..5523e2f8b 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -101,38 +101,6 @@ protected: -class cThrownEnderPearlEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownEnderPearlEntity); - - cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // tolua_end - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // Teleports the creator where the ender pearl lands. - void TeleportCreator(const Vector3d & a_HitPos); - - // tolua_begin - -} ; - - - - - class cThrownSnowballEntity : public cProjectileEntity { -- cgit v1.2.3 From 2f9580ad650ff69e71991b87d6b554ce080624a3 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:19:45 -0700 Subject: Moved cExpBottleEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 27 +-------------------------- src/Entities/ProjectileEntity.h | 26 -------------------------- src/Entities/ProjectileExpBottle.cpp | 27 +++++++++++++++++++++++++++ src/Entities/ProjectileExpBottle.h | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 52 deletions(-) create mode 100644 src/Entities/ProjectileExpBottle.cpp create mode 100644 src/Entities/ProjectileExpBottle.h (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index d7e1f56a7..6060b56df 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -16,6 +16,7 @@ #include "ProjectileArrow.h" #include "ProjectileEgg.h" #include "ProjectileEnderPearl.h" +#include "ProjectileExpBottle.h" @@ -457,32 +458,6 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cBottleOEnchantingEntity : - -cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - // Spawn an experience orb with a reward between 3 and 11. - m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); - m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); - - Destroy(); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cFireworkEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 5523e2f8b..de0df6cb5 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -128,32 +128,6 @@ protected: -class cExpBottleEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cExpBottleEntity); - - cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - - // tolua_begin - -}; - - - - - class cFireworkEntity : public cProjectileEntity { diff --git a/src/Entities/ProjectileExpBottle.cpp b/src/Entities/ProjectileExpBottle.cpp new file mode 100644 index 000000000..3af2b4a4a --- /dev/null +++ b/src/Entities/ProjectileExpBottle.cpp @@ -0,0 +1,27 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileExpBottle.h" +#include "../World.h" + + + + + +cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // Spawn an experience orb with a reward between 3 and 11. + m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); + m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); + + Destroy(); +} \ No newline at end of file diff --git a/src/Entities/ProjectileExpBottle.h b/src/Entities/ProjectileExpBottle.h new file mode 100644 index 000000000..1f9482bf2 --- /dev/null +++ b/src/Entities/ProjectileExpBottle.h @@ -0,0 +1,33 @@ +// +// ProjectileExpBottle.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cExpBottleEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cExpBottleEntity); + + cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + + // tolua_begin + +}; \ No newline at end of file -- cgit v1.2.3 From 08b77f488041e99d4b53173f85ee9b8bcc3e9493 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:24:44 -0700 Subject: Moved cThrownSnowballEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 48 +------------------------------------ src/Entities/ProjectileEntity.h | 27 --------------------- src/Entities/ProjectileSnowball.cpp | 48 +++++++++++++++++++++++++++++++++++++ src/Entities/ProjectileSnowball.h | 34 ++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 74 deletions(-) create mode 100644 src/Entities/ProjectileSnowball.cpp create mode 100644 src/Entities/ProjectileSnowball.h (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 6060b56df..6b137ebe7 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -17,6 +17,7 @@ #include "ProjectileEgg.h" #include "ProjectileEnderPearl.h" #include "ProjectileExpBottle.h" +#include "ProjectileSnowball.h" @@ -411,53 +412,6 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cThrownSnowballEntity : - -cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); -} - - - - - -void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - if (a_EntityHit.IsMob()) - { - cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType(); - if (MobType == cMonster::mtBlaze) - { - TotalDamage = 3; - } - else if (MobType == cMonster::mtEnderDragon) - { - TotalDamage = 1; - } - } - // TODO: If entity is Ender Crystal, destroy it - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cFireworkEntity : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index de0df6cb5..2c461d546 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -101,33 +101,6 @@ protected: -class cThrownSnowballEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownSnowballEntity); - - cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -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; - - // tolua_begin - -} ; - - - - - class cFireworkEntity : public cProjectileEntity { diff --git a/src/Entities/ProjectileSnowball.cpp b/src/Entities/ProjectileSnowball.cpp new file mode 100644 index 000000000..bc056d289 --- /dev/null +++ b/src/Entities/ProjectileSnowball.cpp @@ -0,0 +1,48 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileSnowball.h" +#include "../World.h" + + + + + +cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); +} + + + + + +void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + if (a_EntityHit.IsMob()) + { + cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType(); + if (MobType == cMonster::mtBlaze) + { + TotalDamage = 3; + } + else if (MobType == cMonster::mtEnderDragon) + { + TotalDamage = 1; + } + } + // TODO: If entity is Ender Crystal, destroy it + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} \ No newline at end of file diff --git a/src/Entities/ProjectileSnowball.h b/src/Entities/ProjectileSnowball.h new file mode 100644 index 000000000..5bc6f0daa --- /dev/null +++ b/src/Entities/ProjectileSnowball.h @@ -0,0 +1,34 @@ +// +// ProjectileEgg.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cThrownSnowballEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownSnowballEntity); + + cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +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; + + // tolua_begin + +} ; \ No newline at end of file -- cgit v1.2.3 From de7eaa573560253c9e78fbfa6614cd60763383bf Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:35:31 -0700 Subject: Moved cFireChargeEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 56 ++--------------------------------- src/Entities/ProjectileEntity.h | 28 ------------------ src/Entities/ProjectileFireCharge.cpp | 50 +++++++++++++++++++++++++++++++ src/Entities/ProjectileFireCharge.h | 36 ++++++++++++++++++++++ 4 files changed, 88 insertions(+), 82 deletions(-) create mode 100644 src/Entities/ProjectileFireCharge.cpp create mode 100644 src/Entities/ProjectileFireCharge.h (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 6b137ebe7..ab7753d41 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -18,6 +18,7 @@ #include "ProjectileEnderPearl.h" #include "ProjectileExpBottle.h" #include "ProjectileSnowball.h" +#include "ProjectileFireCharge.h" @@ -520,57 +521,4 @@ void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a { Destroy(); Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cFireChargeEntity : - -cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkFireCharge, a_Creator, a_X, a_Y, a_Z, 0.3125, 0.3125) -{ - SetSpeed(a_Speed); - SetGravity(0); -} - - - - - -void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - if (m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) - { - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 1); - } -} - - - - - -void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); - - // TODO: Some entities are immune to hits - a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning -} - - - - +} \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 2c461d546..d2cca9c75 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -165,34 +165,6 @@ protected: -class cFireChargeEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cFireChargeEntity); - - cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // tolua_begin - -} ; - - - - // tolua_end diff --git a/src/Entities/ProjectileFireCharge.cpp b/src/Entities/ProjectileFireCharge.cpp new file mode 100644 index 000000000..38ba95724 --- /dev/null +++ b/src/Entities/ProjectileFireCharge.cpp @@ -0,0 +1,50 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileFireCharge.h" +#include "../World.h" + + + + + +cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkFireCharge, a_Creator, a_X, a_Y, a_Z, 0.3125, 0.3125) +{ + SetSpeed(a_Speed); + SetGravity(0); +} + + + + + +void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) + { + m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 1); + } +} + + + + + +void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} + + + + + +void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); + + // TODO: Some entities are immune to hits + a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning +} \ No newline at end of file diff --git a/src/Entities/ProjectileFireCharge.h b/src/Entities/ProjectileFireCharge.h new file mode 100644 index 000000000..6c088c547 --- /dev/null +++ b/src/Entities/ProjectileFireCharge.h @@ -0,0 +1,36 @@ +// +// ProjectileFireCharge.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cFireChargeEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cFireChargeEntity); + + cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // tolua_begin + +} ; \ No newline at end of file -- cgit v1.2.3 From cb93a57963257a905334489fcca8d164999dcf50 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:41:07 -0700 Subject: Moved cGhastFireballEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 44 +------------------------------- src/Entities/ProjectileEntity.h | 31 ---------------------- src/Entities/ProjectileGhastFireball.cpp | 44 ++++++++++++++++++++++++++++++++ src/Entities/ProjectileGhastFireball.h | 38 +++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 74 deletions(-) create mode 100644 src/Entities/ProjectileGhastFireball.cpp create mode 100644 src/Entities/ProjectileGhastFireball.h (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index ab7753d41..3a5ac059b 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -19,6 +19,7 @@ #include "ProjectileExpBottle.h" #include "ProjectileSnowball.h" #include "ProjectileFireCharge.h" +#include "ProjectileGhastFireball.h" @@ -478,47 +479,4 @@ void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) } m_ExplodeTimer++; -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cGhastFireballEntity : - -cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : - super(pkGhastFireball, a_Creator, a_X, a_Y, a_Z, 1, 1) -{ - SetSpeed(a_Speed); - SetGravity(0); -} - - - - - -void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - m_World->DoExplosionAt(1, a_BlockX, a_BlockY, a_BlockZ, true, esGhastFireball, this); -} - - - - - -void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); } \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index d2cca9c75..c9b1588ef 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -134,37 +134,6 @@ private: -class cGhastFireballEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cGhastFireballEntity); - - cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // TODO: Deflecting the fireballs by arrow- or sword- hits - - // tolua_begin - -} ; - - - - - // tolua_end diff --git a/src/Entities/ProjectileGhastFireball.cpp b/src/Entities/ProjectileGhastFireball.cpp new file mode 100644 index 000000000..b8325aea2 --- /dev/null +++ b/src/Entities/ProjectileGhastFireball.cpp @@ -0,0 +1,44 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileGhastFireball.h" +#include "../World.h" + + + + + +cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkGhastFireball, a_Creator, a_X, a_Y, a_Z, 1, 1) +{ + SetSpeed(a_Speed); + SetGravity(0); +} + + + + + +void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + m_World->DoExplosionAt(1, a_BlockX, a_BlockY, a_BlockZ, true, esGhastFireball, this); +} + + + + + +void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} + + + + + +void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} \ No newline at end of file diff --git a/src/Entities/ProjectileGhastFireball.h b/src/Entities/ProjectileGhastFireball.h new file mode 100644 index 000000000..7aee1689a --- /dev/null +++ b/src/Entities/ProjectileGhastFireball.h @@ -0,0 +1,38 @@ +// +// ProjectileGhastFireball.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cGhastFireballEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cGhastFireballEntity); + + cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // TODO: Deflecting the fireballs by arrow- or sword- hits + + // tolua_begin + +} ; \ No newline at end of file -- cgit v1.2.3 From e3c3795aa40e59af86d90b45b209f367563942fb Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:50:05 -0700 Subject: Moved cFireworkEntity out of ProjectileEntity.h --- src/Entities/ProjectileEntity.cpp | 72 +----------------------------------- src/Entities/ProjectileEntity.h | 45 +---------------------- src/Entities/ProjectileFirework.cpp | 73 +++++++++++++++++++++++++++++++++++++ src/Entities/ProjectileFirework.h | 40 ++++++++++++++++++++ 4 files changed, 115 insertions(+), 115 deletions(-) create mode 100644 src/Entities/ProjectileFirework.cpp create mode 100644 src/Entities/ProjectileFirework.h (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 3a5ac059b..4784d4b0c 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -19,6 +19,7 @@ #include "ProjectileExpBottle.h" #include "ProjectileSnowball.h" #include "ProjectileFireCharge.h" +#include "ProjectileFirework.h" #include "ProjectileGhastFireball.h" @@ -408,75 +409,4 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) { // Overriden in arrow UNUSED(a_Dest); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cFireworkEntity : - -cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : -super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), - m_ExplodeTimer(0), - m_FireworkItem(a_Item) -{ -} - - - - - -void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) -{ - int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - int PosY = POSY_TOINT; - - if ((PosY < 0) || (PosY >= cChunkDef::Height)) - { - goto setspeed; - } - - if (m_IsInGround) - { - if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR) - { - m_IsInGround = false; - } - else - { - return; - } - } - else - { - if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR) - { - OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM); - return; - } - } - -setspeed: - AddSpeedY(1); - AddPosition(GetSpeed() * (a_Dt / 1000)); -} - - - - - -void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - - if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) - { - m_World->BroadcastEntityStatus(*this, esFireworkExploding); - Destroy(); - } - - m_ExplodeTimer++; } \ No newline at end of file diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index c9b1588ef..e98652206 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -94,47 +94,4 @@ protected: virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; - // tolua_begin -} ; - - - - - -class cFireworkEntity : - public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cFireworkEntity); - - cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); - const cItem & GetItem(void) const { return m_FireworkItem; } - -protected: - - // cProjectileEntity overrides: - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - -private: - - int m_ExplodeTimer; - cItem m_FireworkItem; - - // tolua_begin - -}; - - - - - -// tolua_end - - - +} ; \ No newline at end of file diff --git a/src/Entities/ProjectileFirework.cpp b/src/Entities/ProjectileFirework.cpp new file mode 100644 index 000000000..e884361c4 --- /dev/null +++ b/src/Entities/ProjectileFirework.cpp @@ -0,0 +1,73 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ProjectileFirework.h" +#include "../World.h" +#include "../Chunk.h" + + + + + +cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : +super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), +m_ExplodeTimer(0), +m_FireworkItem(a_Item) +{ +} + + + + + +void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) +{ + int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; + int PosY = POSY_TOINT; + + if ((PosY < 0) || (PosY >= cChunkDef::Height)) + { + goto setspeed; + } + + if (m_IsInGround) + { + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR) + { + m_IsInGround = false; + } + else + { + return; + } + } + else + { + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR) + { + OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM); + return; + } + } + +setspeed: + AddSpeedY(1); + AddPosition(GetSpeed() * (a_Dt / 1000)); +} + + + + + +void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) + { + m_World->BroadcastEntityStatus(*this, esFireworkExploding); + Destroy(); + } + + m_ExplodeTimer++; +} \ No newline at end of file diff --git a/src/Entities/ProjectileFirework.h b/src/Entities/ProjectileFirework.h new file mode 100644 index 000000000..74a50264b --- /dev/null +++ b/src/Entities/ProjectileFirework.h @@ -0,0 +1,40 @@ +// +// ProjectileFirework.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +class cFireworkEntity : +public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cFireworkEntity); + + cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); + const cItem & GetItem(void) const { return m_FireworkItem; } + +protected: + + // cProjectileEntity overrides: + virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + +private: + + int m_ExplodeTimer; + cItem m_FireworkItem; + + // tolua_begin + +}; \ No newline at end of file -- cgit v1.2.3 From cc39d314aee46ea608dd7d06bcc482a58898202e Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 17:58:06 -0700 Subject: Fixed ToLua issues --- src/Entities/ProjectileArrow.h | 3 ++- src/Entities/ProjectileEgg.h | 6 ++---- src/Entities/ProjectileEnderPearl.h | 6 ++---- src/Entities/ProjectileExpBottle.h | 4 ++-- src/Entities/ProjectileFireCharge.h | 4 ++-- src/Entities/ProjectileFirework.h | 4 ++-- src/Entities/ProjectileGhastFireball.h | 4 ++-- src/Entities/ProjectileSnowball.h | 4 ++-- 8 files changed, 16 insertions(+), 19 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileArrow.h b/src/Entities/ProjectileArrow.h index c08b7acc5..8be0ecb7c 100644 --- a/src/Entities/ProjectileArrow.h +++ b/src/Entities/ProjectileArrow.h @@ -10,6 +10,8 @@ +// tolua_begin + class cArrowEntity : public cProjectileEntity { @@ -91,5 +93,4 @@ protected: virtual void CollectedBy(cPlayer * a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - // tolua_begin }; \ No newline at end of file diff --git a/src/Entities/ProjectileEgg.h b/src/Entities/ProjectileEgg.h index 464526dfc..eac2650d0 100644 --- a/src/Entities/ProjectileEgg.h +++ b/src/Entities/ProjectileEgg.h @@ -10,6 +10,8 @@ +// tolua_begin + class cThrownEggEntity : public cProjectileEntity { @@ -25,8 +27,6 @@ public: protected: - // tolua_end - // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; @@ -34,6 +34,4 @@ protected: // Randomly decides whether to spawn a chicken where the egg lands. void TrySpawnChicken(const Vector3d & a_HitPos); - // tolua_begin - } ; \ No newline at end of file diff --git a/src/Entities/ProjectileEnderPearl.h b/src/Entities/ProjectileEnderPearl.h index d6d052428..3ebf0fb3f 100644 --- a/src/Entities/ProjectileEnderPearl.h +++ b/src/Entities/ProjectileEnderPearl.h @@ -10,6 +10,8 @@ +// tolua_begin + class cThrownEnderPearlEntity : public cProjectileEntity { @@ -25,8 +27,6 @@ public: protected: - // tolua_end - // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; @@ -34,6 +34,4 @@ protected: // Teleports the creator where the ender pearl lands. void TeleportCreator(const Vector3d & a_HitPos); - // tolua_begin - } ; \ No newline at end of file diff --git a/src/Entities/ProjectileExpBottle.h b/src/Entities/ProjectileExpBottle.h index 1f9482bf2..94843c51b 100644 --- a/src/Entities/ProjectileExpBottle.h +++ b/src/Entities/ProjectileExpBottle.h @@ -10,6 +10,8 @@ +// tolua_begin + class cExpBottleEntity : public cProjectileEntity { @@ -28,6 +30,4 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - // tolua_begin - }; \ No newline at end of file diff --git a/src/Entities/ProjectileFireCharge.h b/src/Entities/ProjectileFireCharge.h index 6c088c547..ba556f228 100644 --- a/src/Entities/ProjectileFireCharge.h +++ b/src/Entities/ProjectileFireCharge.h @@ -10,6 +10,8 @@ +// tolua_begin + class cFireChargeEntity : public cProjectileEntity { @@ -31,6 +33,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - // tolua_begin - } ; \ No newline at end of file diff --git a/src/Entities/ProjectileFirework.h b/src/Entities/ProjectileFirework.h index 74a50264b..fe90a44a1 100644 --- a/src/Entities/ProjectileFirework.h +++ b/src/Entities/ProjectileFirework.h @@ -10,6 +10,8 @@ +// tolua_begin + class cFireworkEntity : public cProjectileEntity { @@ -35,6 +37,4 @@ private: int m_ExplodeTimer; cItem m_FireworkItem; - // tolua_begin - }; \ No newline at end of file diff --git a/src/Entities/ProjectileGhastFireball.h b/src/Entities/ProjectileGhastFireball.h index 7aee1689a..f37eb42c9 100644 --- a/src/Entities/ProjectileGhastFireball.h +++ b/src/Entities/ProjectileGhastFireball.h @@ -10,6 +10,8 @@ +// tolua_begin + class cGhastFireballEntity : public cProjectileEntity { @@ -33,6 +35,4 @@ protected: // TODO: Deflecting the fireballs by arrow- or sword- hits - // tolua_begin - } ; \ No newline at end of file diff --git a/src/Entities/ProjectileSnowball.h b/src/Entities/ProjectileSnowball.h index 5bc6f0daa..392bd8462 100644 --- a/src/Entities/ProjectileSnowball.h +++ b/src/Entities/ProjectileSnowball.h @@ -10,6 +10,8 @@ +// tolua_begin + class cThrownSnowballEntity : public cProjectileEntity { @@ -29,6 +31,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - // tolua_begin - } ; \ No newline at end of file -- cgit v1.2.3 From 15324f3bbdaf7529636cc1930e1c1b87ef911d86 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 27 Apr 2014 09:42:31 -0700 Subject: Fixed ToLua errors, added newlines --- src/Entities/ProjectileArrow.cpp | 2 +- src/Entities/ProjectileArrow.h | 2 +- src/Entities/ProjectileEgg.cpp | 2 +- src/Entities/ProjectileEgg.h | 2 +- src/Entities/ProjectileEnderPearl.cpp | 2 +- src/Entities/ProjectileEnderPearl.h | 2 +- src/Entities/ProjectileEntity.cpp | 2 +- src/Entities/ProjectileEntity.h | 2 +- src/Entities/ProjectileExpBottle.cpp | 2 +- src/Entities/ProjectileExpBottle.h | 2 +- src/Entities/ProjectileFireCharge.cpp | 2 +- src/Entities/ProjectileFireCharge.h | 2 +- src/Entities/ProjectileFirework.cpp | 2 +- src/Entities/ProjectileFirework.h | 2 +- src/Entities/ProjectileGhastFireball.cpp | 2 +- src/Entities/ProjectileGhastFireball.h | 2 +- src/Entities/ProjectileSnowball.cpp | 2 +- src/Entities/ProjectileSnowball.h | 4 ++-- 18 files changed, 19 insertions(+), 19 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileArrow.cpp b/src/Entities/ProjectileArrow.cpp index bd4f2abab..8bf680797 100644 --- a/src/Entities/ProjectileArrow.cpp +++ b/src/Entities/ProjectileArrow.cpp @@ -190,4 +190,4 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) m_IsInGround = false; // Yes, begin simulating physics again } } -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileArrow.h b/src/Entities/ProjectileArrow.h index 8be0ecb7c..18c30feae 100644 --- a/src/Entities/ProjectileArrow.h +++ b/src/Entities/ProjectileArrow.h @@ -93,4 +93,4 @@ protected: virtual void CollectedBy(cPlayer * a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; -}; \ No newline at end of file +}; // tolua_export diff --git a/src/Entities/ProjectileEgg.cpp b/src/Entities/ProjectileEgg.cpp index 61d61e1c6..3f6e6525e 100644 --- a/src/Entities/ProjectileEgg.cpp +++ b/src/Entities/ProjectileEgg.cpp @@ -56,4 +56,4 @@ void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) 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); } -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileEgg.h b/src/Entities/ProjectileEgg.h index eac2650d0..ba1f6420e 100644 --- a/src/Entities/ProjectileEgg.h +++ b/src/Entities/ProjectileEgg.h @@ -34,4 +34,4 @@ protected: // Randomly decides whether to spawn a chicken where the egg lands. void TrySpawnChicken(const Vector3d & a_HitPos); -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileEnderPearl.cpp b/src/Entities/ProjectileEnderPearl.cpp index 4e848f189..db32f47b7 100644 --- a/src/Entities/ProjectileEnderPearl.cpp +++ b/src/Entities/ProjectileEnderPearl.cpp @@ -51,4 +51,4 @@ void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) 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); } -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileEnderPearl.h b/src/Entities/ProjectileEnderPearl.h index 3ebf0fb3f..39761ff48 100644 --- a/src/Entities/ProjectileEnderPearl.h +++ b/src/Entities/ProjectileEnderPearl.h @@ -34,4 +34,4 @@ protected: // Teleports the creator where the ender pearl lands. void TeleportCreator(const Vector3d & a_HitPos); -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 4784d4b0c..b2e6d469e 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -409,4 +409,4 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest) { // Overriden in arrow UNUSED(a_Dest); -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index e98652206..ae06b072f 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -94,4 +94,4 @@ protected: virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileExpBottle.cpp b/src/Entities/ProjectileExpBottle.cpp index 3af2b4a4a..936be6a72 100644 --- a/src/Entities/ProjectileExpBottle.cpp +++ b/src/Entities/ProjectileExpBottle.cpp @@ -24,4 +24,4 @@ void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_H m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); Destroy(); -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileExpBottle.h b/src/Entities/ProjectileExpBottle.h index 94843c51b..070c412e4 100644 --- a/src/Entities/ProjectileExpBottle.h +++ b/src/Entities/ProjectileExpBottle.h @@ -30,4 +30,4 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; -}; \ No newline at end of file +}; // tolua_export diff --git a/src/Entities/ProjectileFireCharge.cpp b/src/Entities/ProjectileFireCharge.cpp index 38ba95724..5bdb74462 100644 --- a/src/Entities/ProjectileFireCharge.cpp +++ b/src/Entities/ProjectileFireCharge.cpp @@ -47,4 +47,4 @@ void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hi // TODO: Some entities are immune to hits a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileFireCharge.h b/src/Entities/ProjectileFireCharge.h index ba556f228..bcf2b7af6 100644 --- a/src/Entities/ProjectileFireCharge.h +++ b/src/Entities/ProjectileFireCharge.h @@ -33,4 +33,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileFirework.cpp b/src/Entities/ProjectileFirework.cpp index e884361c4..dcb89fce3 100644 --- a/src/Entities/ProjectileFirework.cpp +++ b/src/Entities/ProjectileFirework.cpp @@ -70,4 +70,4 @@ void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) } m_ExplodeTimer++; -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileFirework.h b/src/Entities/ProjectileFirework.h index fe90a44a1..e7d7eacbf 100644 --- a/src/Entities/ProjectileFirework.h +++ b/src/Entities/ProjectileFirework.h @@ -37,4 +37,4 @@ private: int m_ExplodeTimer; cItem m_FireworkItem; -}; \ No newline at end of file +}; // tolua_export diff --git a/src/Entities/ProjectileGhastFireball.cpp b/src/Entities/ProjectileGhastFireball.cpp index b8325aea2..cac622562 100644 --- a/src/Entities/ProjectileGhastFireball.cpp +++ b/src/Entities/ProjectileGhastFireball.cpp @@ -41,4 +41,4 @@ void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a { Destroy(); Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileGhastFireball.h b/src/Entities/ProjectileGhastFireball.h index f37eb42c9..6dd37783e 100644 --- a/src/Entities/ProjectileGhastFireball.h +++ b/src/Entities/ProjectileGhastFireball.h @@ -35,4 +35,4 @@ protected: // TODO: Deflecting the fireballs by arrow- or sword- hits -} ; \ No newline at end of file +} ; // tolua_export diff --git a/src/Entities/ProjectileSnowball.cpp b/src/Entities/ProjectileSnowball.cpp index bc056d289..536b9e791 100644 --- a/src/Entities/ProjectileSnowball.cpp +++ b/src/Entities/ProjectileSnowball.cpp @@ -45,4 +45,4 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); -} \ No newline at end of file +} diff --git a/src/Entities/ProjectileSnowball.h b/src/Entities/ProjectileSnowball.h index 392bd8462..2443d05c6 100644 --- a/src/Entities/ProjectileSnowball.h +++ b/src/Entities/ProjectileSnowball.h @@ -1,5 +1,5 @@ // -// ProjectileEgg.h +// ProjectileSnowball.h // #pragma once @@ -31,4 +31,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; -} ; \ No newline at end of file +} ; // tolua_export -- cgit v1.2.3 From 9dc9713a9c3015d2b67fc18fc2fb8f3b5ce8d734 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Apr 2014 23:12:52 +0200 Subject: Fixed warnings. --- src/Entities/Entity.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 827b88717..2d325805b 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -443,6 +443,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) } } ASSERT(!"Invalid damage type!"); + return false; } -- cgit v1.2.3 From 9b0cb3fd97701370915a9a5b3d5b237fa7f90e06 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 27 Apr 2014 17:03:06 -0700 Subject: Fixed projectile source filenames, indentations --- src/Entities/ArrowEntity.cpp | 193 +++++++++++++++++++++++++++++++ src/Entities/ArrowEntity.h | 96 +++++++++++++++ src/Entities/ExpBottleEntity.cpp | 27 +++++ src/Entities/ExpBottleEntity.h | 33 ++++++ src/Entities/FireChargeEntity.cpp | 50 ++++++++ src/Entities/FireChargeEntity.h | 36 ++++++ src/Entities/FireworkEntity.cpp | 73 ++++++++++++ src/Entities/FireworkEntity.h | 40 +++++++ src/Entities/GhastFireballEntity.cpp | 44 +++++++ src/Entities/GhastFireballEntity.h | 38 ++++++ src/Entities/ProjectileArrow.cpp | 193 ------------------------------- src/Entities/ProjectileArrow.h | 96 --------------- src/Entities/ProjectileEgg.cpp | 59 ---------- src/Entities/ProjectileEgg.h | 37 ------ src/Entities/ProjectileEnderPearl.cpp | 54 --------- src/Entities/ProjectileEnderPearl.h | 37 ------ src/Entities/ProjectileEntity.cpp | 16 +-- src/Entities/ProjectileExpBottle.cpp | 27 ----- src/Entities/ProjectileExpBottle.h | 33 ------ src/Entities/ProjectileFireCharge.cpp | 50 -------- src/Entities/ProjectileFireCharge.h | 36 ------ src/Entities/ProjectileFirework.cpp | 73 ------------ src/Entities/ProjectileFirework.h | 40 ------- src/Entities/ProjectileGhastFireball.cpp | 44 ------- src/Entities/ProjectileGhastFireball.h | 38 ------ src/Entities/ProjectileSnowball.cpp | 48 -------- src/Entities/ProjectileSnowball.h | 34 ------ src/Entities/ThrownEggEntity.cpp | 59 ++++++++++ src/Entities/ThrownEggEntity.h | 37 ++++++ src/Entities/ThrownEnderPearlEntity.cpp | 54 +++++++++ src/Entities/ThrownEnderPearlEntity.h | 37 ++++++ src/Entities/ThrownSnowballEntity.cpp | 48 ++++++++ src/Entities/ThrownSnowballEntity.h | 34 ++++++ 33 files changed, 907 insertions(+), 907 deletions(-) create mode 100644 src/Entities/ArrowEntity.cpp create mode 100644 src/Entities/ArrowEntity.h create mode 100644 src/Entities/ExpBottleEntity.cpp create mode 100644 src/Entities/ExpBottleEntity.h create mode 100644 src/Entities/FireChargeEntity.cpp create mode 100644 src/Entities/FireChargeEntity.h create mode 100644 src/Entities/FireworkEntity.cpp create mode 100644 src/Entities/FireworkEntity.h create mode 100644 src/Entities/GhastFireballEntity.cpp create mode 100644 src/Entities/GhastFireballEntity.h delete mode 100644 src/Entities/ProjectileArrow.cpp delete mode 100644 src/Entities/ProjectileArrow.h delete mode 100644 src/Entities/ProjectileEgg.cpp delete mode 100644 src/Entities/ProjectileEgg.h delete mode 100644 src/Entities/ProjectileEnderPearl.cpp delete mode 100644 src/Entities/ProjectileEnderPearl.h delete mode 100644 src/Entities/ProjectileExpBottle.cpp delete mode 100644 src/Entities/ProjectileExpBottle.h delete mode 100644 src/Entities/ProjectileFireCharge.cpp delete mode 100644 src/Entities/ProjectileFireCharge.h delete mode 100644 src/Entities/ProjectileFirework.cpp delete mode 100644 src/Entities/ProjectileFirework.h delete mode 100644 src/Entities/ProjectileGhastFireball.cpp delete mode 100644 src/Entities/ProjectileGhastFireball.h delete mode 100644 src/Entities/ProjectileSnowball.cpp delete mode 100644 src/Entities/ProjectileSnowball.h create mode 100644 src/Entities/ThrownEggEntity.cpp create mode 100644 src/Entities/ThrownEggEntity.h create mode 100644 src/Entities/ThrownEnderPearlEntity.cpp create mode 100644 src/Entities/ThrownEnderPearlEntity.h create mode 100644 src/Entities/ThrownSnowballEntity.cpp create mode 100644 src/Entities/ThrownSnowballEntity.h (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp new file mode 100644 index 000000000..847b39bbc --- /dev/null +++ b/src/Entities/ArrowEntity.cpp @@ -0,0 +1,193 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "Player.h" +#include "ArrowEntity.h" +#include "../Chunk.h" + + + + + +cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5), + m_PickupState(psNoPickup), + m_DamageCoeff(2), + m_IsCritical(false), + m_Timer(0), + m_HitGroundTimer(0), + m_bIsCollected(false), + m_HitBlockPos(Vector3i(0, 0, 0)) +{ + SetSpeed(a_Speed); + SetMass(0.1); + SetYawFromSpeed(); + SetPitchFromSpeed(); + LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", + m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), + GetYaw(), GetPitch() + ); +} + + + + + +cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : + super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), + m_PickupState(psInSurvivalOrCreative), + m_DamageCoeff(2), + m_IsCritical((a_Force >= 1)), + m_Timer(0), + m_HitGroundTimer(0), + m_HasTeleported(false), + m_bIsCollected(false), + m_HitBlockPos(0, 0, 0) +{ +} + + + + + +bool cArrowEntity::CanPickup(const cPlayer & a_Player) const +{ + switch (m_PickupState) + { + case psNoPickup: return false; + case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); + case psInCreative: return a_Player.IsGameModeCreative(); + } + ASSERT(!"Unhandled pickup state"); + return false; +} + + + + + +void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + if (a_HitFace == BLOCK_FACE_NONE) { return; } + + super::OnHitSolidBlock(a_HitPos, a_HitFace); + int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z; + + switch (a_HitFace) + { + case BLOCK_FACE_XM: // Strangely, bounding boxes / block tracers return the actual block for these two directions, so AddFace not needed + case BLOCK_FACE_YM: + { + break; + } + default: AddFaceDirection(a_X, a_Y, a_Z, a_HitFace, true); + } + + m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); + + // Broadcast arrow hit sound + m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); +} + + + + + +void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat()) + { + // Not an entity that interacts with an arrow + return; + } + + int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); + if (m_IsCritical) + { + Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); + } + a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); + + // Broadcast successful hit sound + m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + + Destroy(); +} + + + + + +void cArrowEntity::CollectedBy(cPlayer * a_Dest) +{ + if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) + { + int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); + if (NumAdded > 0) // Only play effects if there was space in inventory + { + m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); + // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) + m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_bIsCollected = true; + } + } +} + + + + + +void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + m_Timer += a_Dt; + + if (m_bIsCollected) + { + if (m_Timer > 500.f) // 0.5 seconds + { + Destroy(); + return; + } + } + else if (m_Timer > 1000 * 60 * 5) // 5 minutes + { + Destroy(); + return; + } + + if (m_IsInGround) + { + // When an arrow hits, the client doesn't think its in the ground and keeps on moving, IF BroadcastMovementUpdate() and TeleportEntity was called during flight, AT ALL + // Fix is to simply not sync with the client and send a teleport to confirm pos after arrow has stabilised (around 1 sec after landing) + // 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_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_HasTeleported = true; + } + else + { + m_HitGroundTimer += a_Dt; + } + } + + int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; + int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; + cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); + + if (Chunk == NULL) + { + // Inside an unloaded chunk, abort + return; + } + + if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? + { + m_IsInGround = false; // Yes, begin simulating physics again + } + } +} diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h new file mode 100644 index 000000000..1fe3032ee --- /dev/null +++ b/src/Entities/ArrowEntity.h @@ -0,0 +1,96 @@ +// +// ArrowEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cArrowEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field + enum ePickupState + { + psNoPickup = 0, + psInSurvivalOrCreative = 1, + psInCreative = 2, + } ; + + // tolua_end + + CLASS_PROTODEF(cArrowEntity); + + /// Creates a new arrow with psNoPickup state and default damage modifier coeff + cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + + /// Creates a new arrow as shot by a player, initializes it from the player object + cArrowEntity(cPlayer & a_Player, double a_Force); + + // tolua_begin + + /// Returns whether the arrow can be picked up by players + ePickupState GetPickupState(void) const { return m_PickupState; } + + /// Sets a new pickup state + void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; } + + /// Returns the damage modifier coeff. + double GetDamageCoeff(void) const { return m_DamageCoeff; } + + /// Sets the damage modifier coeff + void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; } + + /// Returns true if the specified player can pick the arrow up + bool CanPickup(const cPlayer & a_Player) const; + + /// Returns true if the arrow is set as critical + bool IsCritical(void) const { return m_IsCritical; } + + /// Sets the IsCritical flag + void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; } + + // tolua_end + +protected: + + /// Determines when the arrow can be picked up by players + ePickupState m_PickupState; + + /// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow + double m_DamageCoeff; + + /// If true, the arrow deals more damage + bool m_IsCritical; + + /// Timer for pickup collection animation or five minute timeout + float m_Timer; + + /// 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; + + /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air + Vector3i m_HitBlockPos; + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + virtual void CollectedBy(cPlayer * a_Player) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + +}; // tolua_export diff --git a/src/Entities/ExpBottleEntity.cpp b/src/Entities/ExpBottleEntity.cpp new file mode 100644 index 000000000..202dde942 --- /dev/null +++ b/src/Entities/ExpBottleEntity.cpp @@ -0,0 +1,27 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ExpBottleEntity.h" +#include "../World.h" + + + + + +cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // Spawn an experience orb with a reward between 3 and 11. + m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); + m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); + + Destroy(); +} diff --git a/src/Entities/ExpBottleEntity.h b/src/Entities/ExpBottleEntity.h new file mode 100644 index 000000000..b2043d8f1 --- /dev/null +++ b/src/Entities/ExpBottleEntity.h @@ -0,0 +1,33 @@ +// +// ExpBottleEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cExpBottleEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cExpBottleEntity); + + cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + +}; // tolua_export diff --git a/src/Entities/FireChargeEntity.cpp b/src/Entities/FireChargeEntity.cpp new file mode 100644 index 000000000..aba32602f --- /dev/null +++ b/src/Entities/FireChargeEntity.cpp @@ -0,0 +1,50 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "FireChargeEntity.h" +#include "../World.h" + + + + + +cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkFireCharge, a_Creator, a_X, a_Y, a_Z, 0.3125, 0.3125) +{ + SetSpeed(a_Speed); + SetGravity(0); +} + + + + + +void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) + { + m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 1); + } +} + + + + + +void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} + + + + + +void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); + + // TODO: Some entities are immune to hits + a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning +} diff --git a/src/Entities/FireChargeEntity.h b/src/Entities/FireChargeEntity.h new file mode 100644 index 000000000..3924c337c --- /dev/null +++ b/src/Entities/FireChargeEntity.h @@ -0,0 +1,36 @@ +// +// FireChargeEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cFireChargeEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cFireChargeEntity); + + cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + +} ; // tolua_export diff --git a/src/Entities/FireworkEntity.cpp b/src/Entities/FireworkEntity.cpp new file mode 100644 index 000000000..403a53c84 --- /dev/null +++ b/src/Entities/FireworkEntity.cpp @@ -0,0 +1,73 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "FireworkEntity.h" +#include "../World.h" +#include "../Chunk.h" + + + + + +cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : + super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), + m_ExplodeTimer(0), + m_FireworkItem(a_Item) +{ +} + + + + + +void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) +{ + int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; + int PosY = POSY_TOINT; + + if ((PosY < 0) || (PosY >= cChunkDef::Height)) + { + goto setspeed; + } + + if (m_IsInGround) + { + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR) + { + m_IsInGround = false; + } + else + { + return; + } + } + else + { + if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR) + { + OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM); + return; + } + } + +setspeed: + AddSpeedY(1); + AddPosition(GetSpeed() * (a_Dt / 1000)); +} + + + + + +void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) + { + m_World->BroadcastEntityStatus(*this, esFireworkExploding); + Destroy(); + } + + m_ExplodeTimer++; +} diff --git a/src/Entities/FireworkEntity.h b/src/Entities/FireworkEntity.h new file mode 100644 index 000000000..c62ca9402 --- /dev/null +++ b/src/Entities/FireworkEntity.h @@ -0,0 +1,40 @@ +// +// FireworkEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cFireworkEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cFireworkEntity); + + cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); + const cItem & GetItem(void) const { return m_FireworkItem; } + +protected: + + // cProjectileEntity overrides: + virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + +private: + + int m_ExplodeTimer; + cItem m_FireworkItem; + +}; // tolua_export diff --git a/src/Entities/GhastFireballEntity.cpp b/src/Entities/GhastFireballEntity.cpp new file mode 100644 index 000000000..9e4cb387e --- /dev/null +++ b/src/Entities/GhastFireballEntity.cpp @@ -0,0 +1,44 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "GhastFireballEntity.h" +#include "../World.h" + + + + + +cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkGhastFireball, a_Creator, a_X, a_Y, a_Z, 1, 1) +{ + SetSpeed(a_Speed); + SetGravity(0); +} + + + + + +void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + m_World->DoExplosionAt(1, a_BlockX, a_BlockY, a_BlockZ, true, esGhastFireball, this); +} + + + + + +void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} + + + + + +void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + Destroy(); + Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); +} diff --git a/src/Entities/GhastFireballEntity.h b/src/Entities/GhastFireballEntity.h new file mode 100644 index 000000000..9e4572c78 --- /dev/null +++ b/src/Entities/GhastFireballEntity.h @@ -0,0 +1,38 @@ +// +// GhastFireballEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cGhastFireballEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cGhastFireballEntity); + + cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + // TODO: Deflecting the fireballs by arrow- or sword- hits + +} ; // tolua_export diff --git a/src/Entities/ProjectileArrow.cpp b/src/Entities/ProjectileArrow.cpp deleted file mode 100644 index 8bf680797..000000000 --- a/src/Entities/ProjectileArrow.cpp +++ /dev/null @@ -1,193 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "Player.h" -#include "ProjectileArrow.h" -#include "../Chunk.h" - - - - - -cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5), -m_PickupState(psNoPickup), -m_DamageCoeff(2), -m_IsCritical(false), -m_Timer(0), -m_HitGroundTimer(0), -m_bIsCollected(false), -m_HitBlockPos(Vector3i(0, 0, 0)) -{ - SetSpeed(a_Speed); - SetMass(0.1); - SetYawFromSpeed(); - SetPitchFromSpeed(); - LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", - m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), - GetYaw(), GetPitch() - ); -} - - - - - -cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : -super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5), -m_PickupState(psInSurvivalOrCreative), -m_DamageCoeff(2), -m_IsCritical((a_Force >= 1)), -m_Timer(0), -m_HitGroundTimer(0), -m_HasTeleported(false), -m_bIsCollected(false), -m_HitBlockPos(0, 0, 0) -{ -} - - - - - -bool cArrowEntity::CanPickup(const cPlayer & a_Player) const -{ - switch (m_PickupState) - { - case psNoPickup: return false; - case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); - case psInCreative: return a_Player.IsGameModeCreative(); - } - ASSERT(!"Unhandled pickup state"); - return false; -} - - - - - -void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - if (a_HitFace == BLOCK_FACE_NONE) { return; } - - super::OnHitSolidBlock(a_HitPos, a_HitFace); - int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z; - - switch (a_HitFace) - { - case BLOCK_FACE_XM: // Strangely, bounding boxes / block tracers return the actual block for these two directions, so AddFace not needed - case BLOCK_FACE_YM: - { - break; - } - default: AddFaceDirection(a_X, a_Y, a_Z, a_HitFace, true); - } - - m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); - - // Broadcast arrow hit sound - m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); -} - - - - - -void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat()) - { - // Not an entity that interacts with an arrow - return; - } - - int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); - if (m_IsCritical) - { - Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); - } - a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); - - // Broadcast successful hit sound - m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - - Destroy(); -} - - - - - -void cArrowEntity::CollectedBy(cPlayer * a_Dest) -{ - if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) - { - int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); - if (NumAdded > 0) // Only play effects if there was space in inventory - { - m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); - // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) - m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - m_bIsCollected = true; - } - } -} - - - - - -void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - m_Timer += a_Dt; - - if (m_bIsCollected) - { - if (m_Timer > 500.f) // 0.5 seconds - { - Destroy(); - return; - } - } - else if (m_Timer > 1000 * 60 * 5) // 5 minutes - { - Destroy(); - return; - } - - if (m_IsInGround) - { - // When an arrow hits, the client doesn't think its in the ground and keeps on moving, IF BroadcastMovementUpdate() and TeleportEntity was called during flight, AT ALL - // Fix is to simply not sync with the client and send a teleport to confirm pos after arrow has stabilised (around 1 sec after landing) - // 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_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_HasTeleported = true; - } - else - { - m_HitGroundTimer += a_Dt; - } - } - - int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; - int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; - cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); - - if (Chunk == NULL) - { - // Inside an unloaded chunk, abort - return; - } - - if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? - { - m_IsInGround = false; // Yes, begin simulating physics again - } - } -} diff --git a/src/Entities/ProjectileArrow.h b/src/Entities/ProjectileArrow.h deleted file mode 100644 index 18c30feae..000000000 --- a/src/Entities/ProjectileArrow.h +++ /dev/null @@ -1,96 +0,0 @@ -// -// ProjectileArrow.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cArrowEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field - enum ePickupState - { - psNoPickup = 0, - psInSurvivalOrCreative = 1, - psInCreative = 2, - } ; - - // tolua_end - - CLASS_PROTODEF(cArrowEntity); - - /// Creates a new arrow with psNoPickup state and default damage modifier coeff - cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - - /// Creates a new arrow as shot by a player, initializes it from the player object - cArrowEntity(cPlayer & a_Player, double a_Force); - - // tolua_begin - - /// Returns whether the arrow can be picked up by players - ePickupState GetPickupState(void) const { return m_PickupState; } - - /// Sets a new pickup state - void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; } - - /// Returns the damage modifier coeff. - double GetDamageCoeff(void) const { return m_DamageCoeff; } - - /// Sets the damage modifier coeff - void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; } - - /// Returns true if the specified player can pick the arrow up - bool CanPickup(const cPlayer & a_Player) const; - - /// Returns true if the arrow is set as critical - bool IsCritical(void) const { return m_IsCritical; } - - /// Sets the IsCritical flag - void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; } - - // tolua_end - -protected: - - /// Determines when the arrow can be picked up by players - ePickupState m_PickupState; - - /// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow - double m_DamageCoeff; - - /// If true, the arrow deals more damage - bool m_IsCritical; - - /// Timer for pickup collection animation or five minute timeout - float m_Timer; - - /// 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; - - /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air - Vector3i m_HitBlockPos; - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void CollectedBy(cPlayer * a_Player) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - -}; // tolua_export diff --git a/src/Entities/ProjectileEgg.cpp b/src/Entities/ProjectileEgg.cpp deleted file mode 100644 index 3f6e6525e..000000000 --- a/src/Entities/ProjectileEgg.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileEgg.h" -#include "../World.h" - - - - - -cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkEgg, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - TrySpawnChicken(a_HitPos); - - Destroy(); -} - - - - - -void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - // TODO: If entity is Ender Crystal, destroy it - - TrySpawnChicken(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - -void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) -{ - if (m_World->GetTickRandomNumber(7) == 1) - { - m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); - } - else if (m_World->GetTickRandomNumber(32) == 1) - { - 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); - 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); - } -} diff --git a/src/Entities/ProjectileEgg.h b/src/Entities/ProjectileEgg.h deleted file mode 100644 index ba1f6420e..000000000 --- a/src/Entities/ProjectileEgg.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// ProjectileEgg.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cThrownEggEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownEggEntity); - - cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -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; - - // Randomly decides whether to spawn a chicken where the egg lands. - void TrySpawnChicken(const Vector3d & a_HitPos); - -} ; // tolua_export diff --git a/src/Entities/ProjectileEnderPearl.cpp b/src/Entities/ProjectileEnderPearl.cpp deleted file mode 100644 index db32f47b7..000000000 --- a/src/Entities/ProjectileEnderPearl.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileEnderPearl.h" - - - - - -cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkEnderPearl, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - // TODO: Tweak a_HitPos based on block face. - TeleportCreator(a_HitPos); - - Destroy(); -} - - - - - -void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - // TODO: If entity is Ender Crystal, destroy it - - TeleportCreator(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} - - - - - -void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) -{ - // Teleport the creator here, make them take 5 damage: - if (m_Creator != NULL) - { - 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); - } -} diff --git a/src/Entities/ProjectileEnderPearl.h b/src/Entities/ProjectileEnderPearl.h deleted file mode 100644 index 39761ff48..000000000 --- a/src/Entities/ProjectileEnderPearl.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// ProjectileEnderPearl.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cThrownEnderPearlEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownEnderPearlEntity); - - cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -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; - - // Teleports the creator where the ender pearl lands. - void TeleportCreator(const Vector3d & a_HitPos); - -} ; // tolua_export diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index b2e6d469e..3e48d310c 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -13,14 +13,14 @@ #include "../ChunkMap.h" #include "../Chunk.h" -#include "ProjectileArrow.h" -#include "ProjectileEgg.h" -#include "ProjectileEnderPearl.h" -#include "ProjectileExpBottle.h" -#include "ProjectileSnowball.h" -#include "ProjectileFireCharge.h" -#include "ProjectileFirework.h" -#include "ProjectileGhastFireball.h" +#include "ArrowEntity.h" +#include "ThrownEggEntity.h" +#include "ThrownEnderPearlEntity.h" +#include "ExpBottleEntity.h" +#include "ThrownSnowballEntity.h" +#include "FireChargeEntity.h" +#include "FireworkEntity.h" +#include "GhastFireballEntity.h" diff --git a/src/Entities/ProjectileExpBottle.cpp b/src/Entities/ProjectileExpBottle.cpp deleted file mode 100644 index 936be6a72..000000000 --- a/src/Entities/ProjectileExpBottle.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileExpBottle.h" -#include "../World.h" - - - - - -cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - // Spawn an experience orb with a reward between 3 and 11. - m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); - m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); - - Destroy(); -} diff --git a/src/Entities/ProjectileExpBottle.h b/src/Entities/ProjectileExpBottle.h deleted file mode 100644 index 070c412e4..000000000 --- a/src/Entities/ProjectileExpBottle.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// ProjectileExpBottle.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cExpBottleEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cExpBottleEntity); - - cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - -}; // tolua_export diff --git a/src/Entities/ProjectileFireCharge.cpp b/src/Entities/ProjectileFireCharge.cpp deleted file mode 100644 index 5bdb74462..000000000 --- a/src/Entities/ProjectileFireCharge.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileFireCharge.h" -#include "../World.h" - - - - - -cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkFireCharge, a_Creator, a_X, a_Y, a_Z, 0.3125, 0.3125) -{ - SetSpeed(a_Speed); - SetGravity(0); -} - - - - - -void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - if (m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) - { - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 1); - } -} - - - - - -void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); - - // TODO: Some entities are immune to hits - a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning -} diff --git a/src/Entities/ProjectileFireCharge.h b/src/Entities/ProjectileFireCharge.h deleted file mode 100644 index bcf2b7af6..000000000 --- a/src/Entities/ProjectileFireCharge.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// ProjectileFireCharge.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cFireChargeEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cFireChargeEntity); - - cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - -} ; // tolua_export diff --git a/src/Entities/ProjectileFirework.cpp b/src/Entities/ProjectileFirework.cpp deleted file mode 100644 index dcb89fce3..000000000 --- a/src/Entities/ProjectileFirework.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileFirework.h" -#include "../World.h" -#include "../Chunk.h" - - - - - -cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : -super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), -m_ExplodeTimer(0), -m_FireworkItem(a_Item) -{ -} - - - - - -void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) -{ - int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - int PosY = POSY_TOINT; - - if ((PosY < 0) || (PosY >= cChunkDef::Height)) - { - goto setspeed; - } - - if (m_IsInGround) - { - if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR) - { - m_IsInGround = false; - } - else - { - return; - } - } - else - { - if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR) - { - OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM); - return; - } - } - -setspeed: - AddSpeedY(1); - AddPosition(GetSpeed() * (a_Dt / 1000)); -} - - - - - -void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - - if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) - { - m_World->BroadcastEntityStatus(*this, esFireworkExploding); - Destroy(); - } - - m_ExplodeTimer++; -} diff --git a/src/Entities/ProjectileFirework.h b/src/Entities/ProjectileFirework.h deleted file mode 100644 index e7d7eacbf..000000000 --- a/src/Entities/ProjectileFirework.h +++ /dev/null @@ -1,40 +0,0 @@ -// -// ProjectileFirework.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cFireworkEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cFireworkEntity); - - cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); - const cItem & GetItem(void) const { return m_FireworkItem; } - -protected: - - // cProjectileEntity overrides: - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - -private: - - int m_ExplodeTimer; - cItem m_FireworkItem; - -}; // tolua_export diff --git a/src/Entities/ProjectileGhastFireball.cpp b/src/Entities/ProjectileGhastFireball.cpp deleted file mode 100644 index cac622562..000000000 --- a/src/Entities/ProjectileGhastFireball.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileGhastFireball.h" -#include "../World.h" - - - - - -cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkGhastFireball, a_Creator, a_X, a_Y, a_Z, 1, 1) -{ - SetSpeed(a_Speed); - SetGravity(0); -} - - - - - -void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) -{ - m_World->DoExplosionAt(1, a_BlockX, a_BlockY, a_BlockZ, true, esGhastFireball, this); -} - - - - - -void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} - - - - - -void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); -} diff --git a/src/Entities/ProjectileGhastFireball.h b/src/Entities/ProjectileGhastFireball.h deleted file mode 100644 index 6dd37783e..000000000 --- a/src/Entities/ProjectileGhastFireball.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// ProjectileGhastFireball.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cGhastFireballEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cGhastFireballEntity); - - cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -protected: - - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); - - // cProjectileEntity overrides: - virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - - // TODO: Deflecting the fireballs by arrow- or sword- hits - -} ; // tolua_export diff --git a/src/Entities/ProjectileSnowball.cpp b/src/Entities/ProjectileSnowball.cpp deleted file mode 100644 index 536b9e791..000000000 --- a/src/Entities/ProjectileSnowball.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "ProjectileSnowball.h" -#include "../World.h" - - - - - -cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : -super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) -{ - SetSpeed(a_Speed); -} - - - - - -void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ - Destroy(); -} - - - - - -void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ - int TotalDamage = 0; - if (a_EntityHit.IsMob()) - { - cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType(); - if (MobType == cMonster::mtBlaze) - { - TotalDamage = 3; - } - else if (MobType == cMonster::mtEnderDragon) - { - TotalDamage = 1; - } - } - // TODO: If entity is Ender Crystal, destroy it - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - - Destroy(true); -} diff --git a/src/Entities/ProjectileSnowball.h b/src/Entities/ProjectileSnowball.h deleted file mode 100644 index 2443d05c6..000000000 --- a/src/Entities/ProjectileSnowball.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// ProjectileSnowball.h -// - -#pragma once - -#include "ProjectileEntity.h" - - - - - -// tolua_begin - -class cThrownSnowballEntity : -public cProjectileEntity -{ - typedef cProjectileEntity super; - -public: - - // tolua_end - - CLASS_PROTODEF(cThrownSnowballEntity); - - cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - -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; - -} ; // tolua_export diff --git a/src/Entities/ThrownEggEntity.cpp b/src/Entities/ThrownEggEntity.cpp new file mode 100644 index 000000000..224019091 --- /dev/null +++ b/src/Entities/ThrownEggEntity.cpp @@ -0,0 +1,59 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ThrownEggEntity.h" +#include "../World.h" + + + + + +cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkEgg, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + TrySpawnChicken(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TrySpawnChicken(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) +{ + if (m_World->GetTickRandomNumber(7) == 1) + { + m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); + } + else if (m_World->GetTickRandomNumber(32) == 1) + { + 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); + 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); + } +} diff --git a/src/Entities/ThrownEggEntity.h b/src/Entities/ThrownEggEntity.h new file mode 100644 index 000000000..5ba8f051b --- /dev/null +++ b/src/Entities/ThrownEggEntity.h @@ -0,0 +1,37 @@ +// +// ThrownEggEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cThrownEggEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownEggEntity); + + cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +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; + + // Randomly decides whether to spawn a chicken where the egg lands. + void TrySpawnChicken(const Vector3d & a_HitPos); + +} ; // tolua_export diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp new file mode 100644 index 000000000..c37161145 --- /dev/null +++ b/src/Entities/ThrownEnderPearlEntity.cpp @@ -0,0 +1,54 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ThrownEnderPearlEntity.h" + + + + + +cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkEnderPearl, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // TODO: Tweak a_HitPos based on block face. + TeleportCreator(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TeleportCreator(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) +{ + // Teleport the creator here, make them take 5 damage: + if (m_Creator != NULL) + { + 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); + } +} diff --git a/src/Entities/ThrownEnderPearlEntity.h b/src/Entities/ThrownEnderPearlEntity.h new file mode 100644 index 000000000..ddee5babe --- /dev/null +++ b/src/Entities/ThrownEnderPearlEntity.h @@ -0,0 +1,37 @@ +// +// ThrownEnderPearlEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cThrownEnderPearlEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownEnderPearlEntity); + + cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +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; + + // Teleports the creator where the ender pearl lands. + void TeleportCreator(const Vector3d & a_HitPos); + +} ; // tolua_export diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp new file mode 100644 index 000000000..427f630f7 --- /dev/null +++ b/src/Entities/ThrownSnowballEntity.cpp @@ -0,0 +1,48 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "ThrownSnowballEntity.h" +#include "../World.h" + + + + + +cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : + super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Destroy(); +} + + + + + +void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + if (a_EntityHit.IsMob()) + { + cMonster::eType MobType = ((cMonster &) a_EntityHit).GetMobType(); + if (MobType == cMonster::mtBlaze) + { + TotalDamage = 3; + } + else if (MobType == cMonster::mtEnderDragon) + { + TotalDamage = 1; + } + } + // TODO: If entity is Ender Crystal, destroy it + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} diff --git a/src/Entities/ThrownSnowballEntity.h b/src/Entities/ThrownSnowballEntity.h new file mode 100644 index 000000000..a09512e37 --- /dev/null +++ b/src/Entities/ThrownSnowballEntity.h @@ -0,0 +1,34 @@ +// +// ThrownSnowballEntity.h +// + +#pragma once + +#include "ProjectileEntity.h" + + + + + +// tolua_begin + +class cThrownSnowballEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cThrownSnowballEntity); + + cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +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; + +} ; // tolua_export -- cgit v1.2.3 From dffd38e53b87b3928542ad5fb5223a6b56f20ac9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 28 Apr 2014 22:21:49 +0200 Subject: Fixed a MSVC warning. --- src/Entities/FallingBlock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index bcdac0291..99bff1100 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -88,7 +88,7 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) AddPosition(GetSpeed() * MilliDt); // If not static (One billionth precision) broadcast movement. - static const float epsilon = 0.000000001; + static const float epsilon = 0.000000001f; if ((fabs(GetSpeedX()) > epsilon) || (fabs(GetSpeedZ()) > epsilon)) { BroadcastMovementUpdate(); -- cgit v1.2.3