diff options
Diffstat (limited to 'src/Mobs')
76 files changed, 1161 insertions, 1109 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index c93985b90..16b83c4a6 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -11,7 +11,15 @@ -cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, const AString & a_SoundAmbient, float a_Width, float a_Height) : +cAggressiveMonster::cAggressiveMonster( + const AString & a_ConfigName, + eMonsterType a_MobType, + const AString & a_SoundHurt, + const AString & a_SoundDeath, + const AString & a_SoundAmbient, + float a_Width, + float a_Height +) : Super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_SoundAmbient, a_Width, a_Height) { m_EMPersonality = AGGRESSIVE; @@ -54,8 +62,9 @@ cMonster * cAggressiveMonster::GetMonsterOfTypeInSight(eMonsterType a_MobType, u class cCallback : public cBlockTracer::cCallbacks { - public: - bool OnNextBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_EntryFace) override + public: + bool OnNextBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_EntryFace) + override { return a_BlockType != E_BLOCK_AIR; } @@ -81,18 +90,18 @@ cMonster * cAggressiveMonster::GetMonsterOfTypeInSight(eMonsterType a_MobType, u Vector3d TargetPosition = Other.GetPosition().addedY(Other.GetHeight()); double TargetDistance = (MyHeadPosition - TargetPosition).SqrLength(); - if ( - (MinimumDistance > TargetDistance) && - (TargetDistance < (a_SightDistance * a_SightDistance)) - ) + if ((MinimumDistance > TargetDistance) && (TargetDistance < (a_SightDistance * a_SightDistance))) { - FoundTarget = & Other; + FoundTarget = &Other; return true; } return false; }; - cBoundingBox CheckZone(GetPosition().addedXZ(-a_SightDistance, -a_SightDistance), GetPosition().addedXZ(a_SightDistance, a_SightDistance)); + cBoundingBox CheckZone( + GetPosition().addedXZ(-a_SightDistance, -a_SightDistance), + GetPosition().addedXZ(a_SightDistance, a_SightDistance) + ); m_World->ForEachEntityInBox(CheckZone, Callback); return FoundTarget; } @@ -120,19 +129,17 @@ void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) CheckEventSeePlayer(a_Chunk); } - if ( - (GetTarget() != nullptr) && - TargetIsInRange() && + if ((GetTarget() != nullptr) && TargetIsInRange() && cLineBlockTracer::LineOfSightTrace( *GetWorld(), GetPosition().addedY(GetHeight()), GetTarget()->GetPosition().addedY(GetTarget()->GetHeight()), (IsNetherNative() ? cLineBlockTracer::losAirWaterLava : cLineBlockTracer::losAirWater) ) && - (GetHealth() > 0.0) - ) + (GetHealth() > 0.0)) { - // Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls) + // Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack + // through walls) Attack(a_Dt); } } diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h index 48ed7932e..8e8588754 100644 --- a/src/Mobs/AggressiveMonster.h +++ b/src/Mobs/AggressiveMonster.h @@ -7,13 +7,11 @@ -class cAggressiveMonster: - public cMonster +class cAggressiveMonster : public cMonster { using Super = cMonster; -public: - + public: cAggressiveMonster( const AString & a_ConfigName, eMonsterType a_MobType, @@ -24,24 +22,24 @@ public: float a_Height ); - virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void InStateChasing(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk) override; /** - * Check if a monster of certain type is in sight - * - * @param a_mobtype the mob type to find - * @param SightDistance max distance to check - * - * @return pointer to the mob found - */ - cMonster * GetMonsterOfTypeInSight(eMonsterType a_mobtype, unsigned int SightDistance=16); + * Check if a monster of certain type is in sight + * + * @param a_mobtype the mob type to find + * @param SightDistance max distance to check + * + * @return pointer to the mob found + */ + cMonster * GetMonsterOfTypeInSight(eMonsterType a_mobtype, unsigned int SightDistance = 16); /** Try to perform attack - returns true if attack was deemed successful (hit player, fired projectile, creeper exploded, etc.) even if it didn't actually do damage - return false if e.g. the mob is still in cooldown from a previous attack */ + returns true if attack was deemed successful (hit player, fired projectile, creeper exploded, etc.) even if it + didn't actually do damage return false if e.g. the mob is still in cooldown from a previous attack */ virtual bool Attack(std::chrono::milliseconds a_Dt); -} ; +}; diff --git a/src/Mobs/Bat.cpp b/src/Mobs/Bat.cpp index 28ae76f6f..fbeb3d7f4 100644 --- a/src/Mobs/Bat.cpp +++ b/src/Mobs/Bat.cpp @@ -11,5 +11,3 @@ cBat::cBat(void) : SetGravity(-2.0f); SetAirDrag(0.05f); } - - diff --git a/src/Mobs/Bat.h b/src/Mobs/Bat.h index 0d57cd6dd..c460e490c 100644 --- a/src/Mobs/Bat.h +++ b/src/Mobs/Bat.h @@ -7,20 +7,14 @@ -class cBat: - public cPassiveMonster +class cBat : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: cBat(); CLASS_PROTODEF(cBat) - bool IsHanging(void) const {return false; } -} ; - - - - + bool IsHanging(void) const { return false; } +}; diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index f5939834a..9c8a9ec71 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -60,11 +60,7 @@ void cBlaze::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) if (m_IsCharging) { m_ChargeTimer++; - if ( - (m_ChargeTimer == 5) || - (m_ChargeTimer == 10) || - (m_ChargeTimer == 15) - ) + if ((m_ChargeTimer == 5) || (m_ChargeTimer == 10) || (m_ChargeTimer == 15)) { Vector3d Speed = GetLookVector() * 20; Speed.y = Speed.y + 1; diff --git a/src/Mobs/Blaze.h b/src/Mobs/Blaze.h index 9ebc1ffcf..35708a4d9 100644 --- a/src/Mobs/Blaze.h +++ b/src/Mobs/Blaze.h @@ -7,19 +7,16 @@ -class cBlaze: - public cAggressiveMonster +class cBlaze : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cBlaze(); CLASS_PROTODEF(cBlaze) -private: - + private: virtual bool Attack(std::chrono::milliseconds a_Dt) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool IsNetherNative(void) override { return true; } @@ -31,4 +28,4 @@ private: /** Number of ticks since the blaze started charging. Used to create 3 successive projectiles. */ int m_ChargeTimer; -} ; +}; diff --git a/src/Mobs/CaveSpider.cpp b/src/Mobs/CaveSpider.cpp index bd9e5f07b..61b8e119c 100644 --- a/src/Mobs/CaveSpider.cpp +++ b/src/Mobs/CaveSpider.cpp @@ -64,7 +64,3 @@ void cCaveSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } } - - - - diff --git a/src/Mobs/CaveSpider.h b/src/Mobs/CaveSpider.h index 3e3fef4ff..474fd5ac0 100644 --- a/src/Mobs/CaveSpider.h +++ b/src/Mobs/CaveSpider.h @@ -6,13 +6,11 @@ -class cCaveSpider: - public cAggressiveMonster +class cCaveSpider : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cCaveSpider(); CLASS_PROTODEF(cCaveSpider) @@ -20,8 +18,4 @@ public: virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual bool Attack(std::chrono::milliseconds a_Dt) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; -} ; - - - - +}; diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index cc9609450..a2f868291 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -33,10 +33,7 @@ void cChicken::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) return; // Babies don't lay eggs } - if ( - ((m_EggDropTimer == 6000) && GetRandomProvider().RandBool()) || - m_EggDropTimer == 12000 - ) + if (((m_EggDropTimer == 6000) && GetRandomProvider().RandBool()) || m_EggDropTimer == 12000) { cItems Drops; m_EggDropTimer = 0; diff --git a/src/Mobs/Chicken.h b/src/Mobs/Chicken.h index 5e84a61c8..c9d54ce5a 100644 --- a/src/Mobs/Chicken.h +++ b/src/Mobs/Chicken.h @@ -6,13 +6,11 @@ -class cChicken: - public cPassiveMonster +class cChicken : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: cChicken(); CLASS_PROTODEF(cChicken) @@ -30,10 +28,6 @@ public: virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; -private: - + private: int m_EggDropTimer; -} ; - - - +}; diff --git a/src/Mobs/Cow.h b/src/Mobs/Cow.h index 657c48cce..f27e186ed 100644 --- a/src/Mobs/Cow.h +++ b/src/Mobs/Cow.h @@ -7,13 +7,11 @@ -class cCow: - public cPassiveMonster +class cCow : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: cCow(); CLASS_PROTODEF(cCow) @@ -21,13 +19,5 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual void OnRightClicked(cPlayer & a_Player) override; - virtual void GetFollowedItems(cItems & a_Items) override - { - a_Items.Add(E_ITEM_WHEAT); - } - -} ; - - - - + virtual void GetFollowedItems(cItems & a_Items) override { a_Items.Add(E_ITEM_WHEAT); } +}; diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 0461bcc2a..7f8c6a3d7 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -76,20 +76,16 @@ void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); // If the creeper was killed by a skeleton, add a random music disc drop: - if ( - (a_Killer != nullptr) && - a_Killer->IsProjectile() && + if ((a_Killer != nullptr) && a_Killer->IsProjectile() && ((static_cast<cProjectileEntity *>(a_Killer))->GetCreatorUniqueID() != cEntity::INVALID_ID)) { auto ProjectileCreatorCallback = [](cEntity & a_Entity) - { - return ( - a_Entity.IsMob() && - ((static_cast<cMonster &>(a_Entity)).GetMobType() == mtSkeleton) - ); - }; - - if (GetWorld()->DoWithEntityByID(static_cast<cProjectileEntity *>(a_Killer)->GetCreatorUniqueID(), ProjectileCreatorCallback)) + { return (a_Entity.IsMob() && ((static_cast<cMonster &>(a_Entity)).GetMobType() == mtSkeleton)); }; + + if (GetWorld()->DoWithEntityByID( + static_cast<cProjectileEntity *>(a_Killer)->GetCreatorUniqueID(), + ProjectileCreatorCallback + )) { AddRandomDropItem(a_Drops, 1, 1, static_cast<short>(m_World->GetTickRandomNumber(11) + E_ITEM_FIRST_DISC)); } @@ -126,7 +122,12 @@ bool cCreeper::Attack(std::chrono::milliseconds a_Dt) if (!m_bIsBlowing) { - m_World->BroadcastSoundEffect("entity.creeper.primed", GetPosition(), 1.f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect( + "entity.creeper.primed", + GetPosition(), + 1.f, + (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64) + ); m_bIsBlowing = true; m_World->BroadcastEntityMetadata(*this); @@ -149,7 +150,12 @@ void cCreeper::OnRightClicked(cPlayer & a_Player) { a_Player.UseEquippedItem(); } - m_World->BroadcastSoundEffect("entity.creeper.primed", GetPosition(), 1.f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect( + "entity.creeper.primed", + GetPosition(), + 1.f, + (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64) + ); m_bIsBlowing = true; m_World->BroadcastEntityMetadata(*this); m_BurnedWithFlintAndSteel = true; diff --git a/src/Mobs/Creeper.h b/src/Mobs/Creeper.h index 5a21cca2a..825f1e07b 100644 --- a/src/Mobs/Creeper.h +++ b/src/Mobs/Creeper.h @@ -7,13 +7,11 @@ -class cCreeper: - public cAggressiveMonster +class cCreeper : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cCreeper(); CLASS_PROTODEF(cCreeper) @@ -24,17 +22,11 @@ public: virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void OnRightClicked(cPlayer & a_Player) override; - bool IsBlowing(void) const {return m_bIsBlowing; } - bool IsCharged(void) const {return m_bIsCharged; } - bool IsBurnedWithFlintAndSteel(void) const {return m_BurnedWithFlintAndSteel; } - -private: + bool IsBlowing(void) const { return m_bIsBlowing; } + bool IsCharged(void) const { return m_bIsCharged; } + bool IsBurnedWithFlintAndSteel(void) const { return m_BurnedWithFlintAndSteel; } + private: bool m_bIsBlowing, m_bIsCharged, m_BurnedWithFlintAndSteel; int m_ExplodingTimer; - -} ; - - - - +}; diff --git a/src/Mobs/EnderDragon.cpp b/src/Mobs/EnderDragon.cpp index 30b3ed0fb..bfd2c9f16 100644 --- a/src/Mobs/EnderDragon.cpp +++ b/src/Mobs/EnderDragon.cpp @@ -10,7 +10,15 @@ cEnderDragon::cEnderDragon(void) : - Super("EnderDragon", mtEnderDragon, "entity.enderdragon.hurt", "entity.enderdragon.death", "entity.enderdragon.ambient", 16, 8) + Super( + "EnderDragon", + mtEnderDragon, + "entity.enderdragon.hurt", + "entity.enderdragon.death", + "entity.enderdragon.ambient", + 16, + 8 + ) { } @@ -47,5 +55,14 @@ void cEnderDragon::SpawnOn(cClientHandle & a_Client) Super::SpawnOn(a_Client); // Red boss bar with no divisions that plays boss music and creates fog: - a_Client.SendBossBarAdd(GetUniqueID(), cCompositeChat("Ender Dragon"), GetHealth() / GetMaxHealth(), BossBarColor::Red, BossBarDivisionType::None, false, true, true); + a_Client.SendBossBarAdd( + GetUniqueID(), + cCompositeChat("Ender Dragon"), + GetHealth() / GetMaxHealth(), + BossBarColor::Red, + BossBarDivisionType::None, + false, + true, + true + ); } diff --git a/src/Mobs/EnderDragon.h b/src/Mobs/EnderDragon.h index ffc39218c..1d90e0026 100644 --- a/src/Mobs/EnderDragon.h +++ b/src/Mobs/EnderDragon.h @@ -7,13 +7,11 @@ -class cEnderDragon: - public cAggressiveMonster +class cEnderDragon : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cEnderDragon(); CLASS_PROTODEF(cEnderDragon) @@ -21,4 +19,4 @@ public: virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual void SpawnOn(cClientHandle & a_Client) override; -} ; +}; diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index 3711d7f07..f601693ca 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -13,16 +13,13 @@ // cPlayerLookCheck class cPlayerLookCheck { -public: - + public: cPlayerLookCheck(Vector3d a_EndermanHeadPosition, int a_SightDistance) : - m_Player(nullptr), - m_EndermanHeadPosition(a_EndermanHeadPosition), - m_SightDistance(a_SightDistance) + m_Player(nullptr), m_EndermanHeadPosition(a_EndermanHeadPosition), m_SightDistance(a_SightDistance) { } - bool operator () (cPlayer & a_Player) + bool operator()(cPlayer & a_Player) { // Don't check players who cannot be targeted if (!a_Player.CanMobsTarget()) @@ -55,7 +52,12 @@ public: } // TODO: Check if endermen are angered through water in Vanilla - if (!cLineBlockTracer::LineOfSightTrace(*a_Player.GetWorld(), m_EndermanHeadPosition, PlayerHeadPosition, cLineBlockTracer::losAirWater)) + if (!cLineBlockTracer::LineOfSightTrace( + *a_Player.GetWorld(), + m_EndermanHeadPosition, + PlayerHeadPosition, + cLineBlockTracer::losAirWater + )) { // No direct line of sight return false; @@ -67,19 +69,26 @@ public: cPlayer * GetPlayer(void) const { return m_Player; } -protected: - + protected: cPlayer * m_Player; Vector3d m_EndermanHeadPosition; int m_SightDistance; -} ; +}; cEnderman::cEnderman(void) : - Super("Enderman", mtEnderman, "entity.endermen.hurt", "entity.endermen.death", "entity.endermen.ambient", 0.6f, 2.9f), + Super( + "Enderman", + mtEnderman, + "entity.endermen.hurt", + "entity.endermen.death", + "entity.endermen.ambient", + 0.6f, + 2.9f + ), m_bIsScreaming(false), m_CarriedBlock(E_BLOCK_AIR), m_CarriedMeta(0) diff --git a/src/Mobs/Enderman.h b/src/Mobs/Enderman.h index 1e2a6f52e..6bd0be193 100644 --- a/src/Mobs/Enderman.h +++ b/src/Mobs/Enderman.h @@ -7,13 +7,11 @@ -class cEnderman: - public cPassiveAggressiveMonster +class cEnderman : public cPassiveAggressiveMonster { using Super = cPassiveAggressiveMonster; -public: - + public: cEnderman(); CLASS_PROTODEF(cEnderman) @@ -23,14 +21,12 @@ public: virtual void EventLosePlayer(void) override; virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - bool IsScreaming(void) const {return m_bIsScreaming; } - BLOCKTYPE GetCarriedBlock(void) const {return m_CarriedBlock; } - NIBBLETYPE GetCarriedMeta(void) const {return m_CarriedMeta; } - -private: + bool IsScreaming(void) const { return m_bIsScreaming; } + BLOCKTYPE GetCarriedBlock(void) const { return m_CarriedBlock; } + NIBBLETYPE GetCarriedMeta(void) const { return m_CarriedMeta; } + private: bool m_bIsScreaming; BLOCKTYPE m_CarriedBlock; NIBBLETYPE m_CarriedMeta; - -} ; +}; diff --git a/src/Mobs/Endermite.cpp b/src/Mobs/Endermite.cpp index 3a89de98a..c511551ee 100644 --- a/src/Mobs/Endermite.cpp +++ b/src/Mobs/Endermite.cpp @@ -13,7 +13,15 @@ cEndermite::cEndermite() : - Super("Endermite", mtEndermite, "entity.endermite.hurt", "entity.endermite.death", "entity.endermite.ambient", 0.4f, 0.3f), + Super( + "Endermite", + mtEndermite, + "entity.endermite.hurt", + "entity.endermite.death", + "entity.endermite.ambient", + 0.4f, + 0.3f + ), m_Timer(0), m_Lifetime(2 * 1000 * 60) // 2 minutes (2 * 1000 (mili to sec) * 60 (sec to min) * 2 because tick = 0.5 sec) { @@ -36,6 +44,5 @@ void cEndermite::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { Destroy(); } - } } diff --git a/src/Mobs/Endermite.h b/src/Mobs/Endermite.h index 9e0102a07..a9e277b7b 100644 --- a/src/Mobs/Endermite.h +++ b/src/Mobs/Endermite.h @@ -5,8 +5,7 @@ -class cEndermite: - public cAggressiveMonster +class cEndermite : public cAggressiveMonster { using Super = cAggressiveMonster; @@ -14,11 +13,10 @@ class cEndermite: std::chrono::milliseconds m_Timer; std::chrono::milliseconds m_Lifetime; -public: - + public: cEndermite(); CLASS_PROTODEF(cEndermite) void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; -} ; +}; diff --git a/src/Mobs/Ghast.h b/src/Mobs/Ghast.h index 755ec3b89..64184bac0 100644 --- a/src/Mobs/Ghast.h +++ b/src/Mobs/Ghast.h @@ -7,21 +7,18 @@ -class cGhast: - public cAggressiveMonster +class cGhast : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cGhast(); CLASS_PROTODEF(cGhast) bool IsCharging(void) const { return m_IsCharging; } -private: - + private: virtual bool Attack(std::chrono::milliseconds a_Dt) override; virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; @@ -37,4 +34,4 @@ private: /** Number of ticks until a projectile is created. Only used while m_IsCharging is true. */ int m_TicksUntilShot; -} ; +}; diff --git a/src/Mobs/Giant.cpp b/src/Mobs/Giant.cpp index ad5e0da54..4237ffe3e 100644 --- a/src/Mobs/Giant.cpp +++ b/src/Mobs/Giant.cpp @@ -10,7 +10,6 @@ cGiant::cGiant(void) : Super("Giant", mtGiant, "entity.zombie.hurt", "entity.zombie.death", "entity.zombie.ambient", 3.6f, 12) { - } @@ -21,7 +20,3 @@ void cGiant::GetDrops(cItems & a_Drops, cEntity * a_Killer) { AddRandomDropItem(a_Drops, 10, 50, E_ITEM_ROTTEN_FLESH); } - - - - diff --git a/src/Mobs/Giant.h b/src/Mobs/Giant.h index 46298717c..18d77fd2c 100644 --- a/src/Mobs/Giant.h +++ b/src/Mobs/Giant.h @@ -7,20 +7,14 @@ -class cGiant: - public cAggressiveMonster +class cGiant : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cGiant(void); CLASS_PROTODEF(cGiant) virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; -} ; - - - - +}; diff --git a/src/Mobs/Guardian.cpp b/src/Mobs/Guardian.cpp index f9c80d1e5..2fe4e3dec 100644 --- a/src/Mobs/Guardian.cpp +++ b/src/Mobs/Guardian.cpp @@ -9,7 +9,15 @@ cGuardian::cGuardian(void) : - Super("Guardian", mtGuardian, "entity.guardian.hurt", "entity.guardian.death", "entity.guardian.ambient", 0.85f, 0.85f) + Super( + "Guardian", + mtGuardian, + "entity.guardian.hurt", + "entity.guardian.death", + "entity.guardian.ambient", + 0.85f, + 0.85f + ) { } @@ -27,7 +35,12 @@ void cGuardian::GetDrops(cItems & a_Drops, cEntity * a_Killer) } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_PRISMARINE_SHARD); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_RAW_FISH); - AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_PRISMARINE_CRYSTALS); // TODO: Prismarine Crystals only drop if the raw fish drop is 0 + AddRandomDropItem( + a_Drops, + 0, + 1 + LootingLevel, + E_ITEM_PRISMARINE_CRYSTALS + ); // TODO: Prismarine Crystals only drop if the raw fish drop is 0 } @@ -50,7 +63,3 @@ void cGuardian::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Super::Tick(a_Dt, a_Chunk); } - - - - diff --git a/src/Mobs/Guardian.h b/src/Mobs/Guardian.h index 5867c1f42..0fd52c582 100644 --- a/src/Mobs/Guardian.h +++ b/src/Mobs/Guardian.h @@ -7,13 +7,11 @@ -class cGuardian: - public cAggressiveMonster +class cGuardian : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cGuardian(); virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; @@ -25,8 +23,4 @@ public: // Guardians do not drown (or float) virtual void HandleAir(void) override {} virtual void SetSwimState(cChunk & a_Chunk) override {} -} ; - - - - +}; diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 9f0507b09..22a14b175 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -67,10 +67,26 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (Random.RandBool(0.02)) { - m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, GetPosition().Floor(), int(SmokeDirection::SOUTH_EAST)); - m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, GetPosition().Floor(), int(SmokeDirection::SOUTH_WEST)); - m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, GetPosition().Floor(), int(SmokeDirection::NORTH_EAST)); - m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, GetPosition().Floor(), int(SmokeDirection::NORTH_WEST)); + m_World->BroadcastSoundParticleEffect( + EffectID::PARTICLE_SMOKE, + GetPosition().Floor(), + int(SmokeDirection::SOUTH_EAST) + ); + m_World->BroadcastSoundParticleEffect( + EffectID::PARTICLE_SMOKE, + GetPosition().Floor(), + int(SmokeDirection::SOUTH_WEST) + ); + m_World->BroadcastSoundParticleEffect( + EffectID::PARTICLE_SMOKE, + GetPosition().Floor(), + int(SmokeDirection::NORTH_EAST) + ); + m_World->BroadcastSoundParticleEffect( + EffectID::PARTICLE_SMOKE, + GetPosition().Floor(), + int(SmokeDirection::NORTH_WEST) + ); m_World->BroadcastSoundEffect("entity.horse.angry", GetPosition(), 1.0f, 1.0f); m_Attachee->Detach(); @@ -80,7 +96,7 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } else { - m_World->BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5); + m_World->BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f {}, 0, 5); MetadataDirty = true; m_bIsTame = true; } @@ -139,13 +155,7 @@ void cHorse::OnRightClicked(cPlayer & a_Player) auto EquipedItemType = a_Player.GetEquippedItem().m_ItemType; - if ( - !IsSaddled() && - ( - (EquipedItemType == E_ITEM_SADDLE) || - ItemCategory::IsHorseArmor(EquipedItemType) - ) - ) + if (!IsSaddled() && ((EquipedItemType == E_ITEM_SADDLE) || ItemCategory::IsHorseArmor(EquipedItemType))) { // Player is holding a horse inventory item, open the window: PlayerOpenWindow(a_Player); diff --git a/src/Mobs/Horse.h b/src/Mobs/Horse.h index 4f35071c0..ae552f0d6 100644 --- a/src/Mobs/Horse.h +++ b/src/Mobs/Horse.h @@ -8,14 +8,12 @@ -class cHorse: - public cPassiveMonster, - public cEntityWindowOwner +class cHorse : public cPassiveMonster, + public cEntityWindowOwner { using Super = cPassiveMonster; -public: - + public: cHorse(int Type, int Color, int Style, int TameTimes); CLASS_PROTODEF(cHorse) @@ -27,16 +25,16 @@ public: virtual void OnRemoveFromWorld(cWorld & a_World) override; virtual void OnRightClicked(cPlayer & a_Player) override; - bool IsSaddled (void) const {return !m_Saddle.IsEmpty(); } - bool IsChested (void) const {return m_bHasChest; } - bool IsEating (void) const {return m_bIsEating; } - bool IsRearing (void) const {return m_bIsRearing; } - bool IsMthOpen (void) const {return m_bIsMouthOpen; } - bool IsTame (void) const override {return m_bIsTame; } - int GetHorseType (void) const {return m_Type; } - int GetHorseColor (void) const {return m_Color; } - int GetHorseStyle (void) const {return m_Style; } - int GetHorseArmour (void) const; + bool IsSaddled(void) const { return !m_Saddle.IsEmpty(); } + bool IsChested(void) const { return m_bHasChest; } + bool IsEating(void) const { return m_bIsEating; } + bool IsRearing(void) const { return m_bIsRearing; } + bool IsMthOpen(void) const { return m_bIsMouthOpen; } + bool IsTame(void) const override { return m_bIsTame; } + int GetHorseType(void) const { return m_Type; } + int GetHorseColor(void) const { return m_Color; } + int GetHorseStyle(void) const { return m_Style; } + int GetHorseArmour(void) const; /** Set the horse's saddle to the given item. @param a_SaddleItem should be either a saddle or empty. */ @@ -46,8 +44,8 @@ public: @param a_SaddleItem should be either a type of horse armor or empty. */ void SetHorseArmor(cItem a_ArmorItem); - const cItem & GetHorseSaddle() const { return m_Saddle; } - const cItem & GetHorseArmorItem() const { return m_Armor; } + const cItem & GetHorseSaddle() const { return m_Saddle; } + const cItem & GetHorseArmorItem() const { return m_Armor; } virtual void GetBreedingItems(cItems & a_Items) override { @@ -57,12 +55,10 @@ public: void PlayerOpenWindow(cPlayer & a_Player); -private: - + private: bool m_bHasChest, m_bIsEating, m_bIsRearing, m_bIsMouthOpen, m_bIsTame; int m_Type, m_Color, m_Style, m_TimesToTame, m_TameAttemptTimes, m_RearTickCount; float m_MaxSpeed; cItem m_Saddle; cItem m_Armor; - -} ; +}; diff --git a/src/Mobs/IronGolem.cpp b/src/Mobs/IronGolem.cpp index 0ad25f822..0797cdaed 100644 --- a/src/Mobs/IronGolem.cpp +++ b/src/Mobs/IronGolem.cpp @@ -8,7 +8,15 @@ cIronGolem::cIronGolem(void) : - Super("IronGolem", mtIronGolem, "entity.irongolem.hurt", "entity.irongolem.death", "entity.irongolem.ambient", 1.4f, 2.7f) + Super( + "IronGolem", + mtIronGolem, + "entity.irongolem.hurt", + "entity.irongolem.death", + "entity.irongolem.ambient", + 1.4f, + 2.7f + ) { } @@ -22,7 +30,3 @@ void cIronGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) AddRandomDropItem(a_Drops, 0, 5, E_ITEM_IRON); AddRandomDropItem(a_Drops, 0, 2, E_BLOCK_FLOWER); } - - - - diff --git a/src/Mobs/IronGolem.h b/src/Mobs/IronGolem.h index 92b0e42fd..17b6f66d5 100644 --- a/src/Mobs/IronGolem.h +++ b/src/Mobs/IronGolem.h @@ -7,13 +7,11 @@ -class cIronGolem: - public cPassiveAggressiveMonster +class cIronGolem : public cPassiveAggressiveMonster { using Super = cPassiveAggressiveMonster; -public: - + public: cIronGolem(); CLASS_PROTODEF(cIronGolem) @@ -23,8 +21,4 @@ public: // Iron golems do not drown nor float virtual void HandleAir(void) override {} virtual void SetSwimState(cChunk & a_Chunk) override {} -} ; - - - - +}; diff --git a/src/Mobs/MagmaCube.cpp b/src/Mobs/MagmaCube.cpp index 28bc63ef9..339fc8136 100644 --- a/src/Mobs/MagmaCube.cpp +++ b/src/Mobs/MagmaCube.cpp @@ -10,7 +10,7 @@ cMagmaCube::cMagmaCube(int a_Size) : Super( "MagmaCube", mtMagmaCube, - fmt::format(FMT_STRING("entity.{}magmacube.hurt"), GetSizeName(a_Size)), + fmt::format(FMT_STRING("entity.{}magmacube.hurt"), GetSizeName(a_Size)), fmt::format(FMT_STRING("entity.{}magmacube.death"), GetSizeName(a_Size)), "", 0.51f * a_Size, diff --git a/src/Mobs/MagmaCube.h b/src/Mobs/MagmaCube.h index 07794cc5a..bf1be2e19 100644 --- a/src/Mobs/MagmaCube.h +++ b/src/Mobs/MagmaCube.h @@ -6,13 +6,11 @@ -class cMagmaCube: - public cAggressiveMonster +class cMagmaCube : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: /** Creates a MagmaCube of the specified size; with 1 being the smallest */ cMagmaCube(int a_Size); @@ -24,11 +22,10 @@ public: Returns either "big" or "small". */ static AString GetSizeName(int a_Size); -private: - + private: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool IsNetherNative(void) override { return true; } /** Size of the MagmaCube, with 1 being the smallest */ int m_Size; -} ; +}; diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 788d1b66f..cbdb062f4 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -36,43 +36,42 @@ static const struct const char * m_lcName; const char * m_VanillaName; const char * m_VanillaNameNBT; -} g_MobTypeNames[] = -{ - {mtBat, "bat", "Bat", "bat"}, - {mtBlaze, "blaze", "Blaze", "blaze"}, - {mtCaveSpider, "cavespider", "CaveSpider", "cave_spider"}, - {mtChicken, "chicken", "Chicken", "chicken"}, - {mtCow, "cow", "Cow", "cow"}, - {mtCreeper, "creeper", "Creeper", "creeper"}, - {mtEnderman, "enderman", "Enderman", "enderman"}, - {mtEndermite, "endermite", "Endermite", "endermite"}, - {mtEnderDragon, "enderdragon", "EnderDragon", "ender_dragon"}, - {mtGhast, "ghast", "Ghast", "ghast"}, - {mtGiant, "giant", "Giant", "giant"}, - {mtGuardian, "guardian", "Guardian", "guardian"}, - {mtHorse, "horse", "EntityHorse", "horse"}, - {mtIronGolem, "irongolem", "VillagerGolem", "iron_golem"}, - {mtMagmaCube, "magmacube", "LavaSlime", "magma_cube"}, - {mtMooshroom, "mooshroom", "MushroomCow", "mooshroom"}, - {mtOcelot, "ocelot", "Ozelot", "ocelot"}, - {mtPig, "pig", "Pig", "pig"}, - {mtRabbit, "rabbit", "Rabbit", "rabbit"}, - {mtSheep, "sheep", "Sheep", "sheep"}, - {mtSilverfish, "silverfish", "Silverfish", "silverfish"}, - {mtSkeleton, "skeleton", "Skeleton", "skeleton"}, - {mtSlime, "slime", "Slime", "slime"}, - {mtSnowGolem, "snowgolem", "SnowMan", "snow_golem"}, - {mtSpider, "spider", "Spider", "spider"}, - {mtSquid, "squid", "Squid", "squid"}, - {mtVillager, "villager", "Villager", "villager"}, - {mtWitch, "witch", "Witch", "witch"}, - {mtWither, "wither", "WitherBoss", "wither"}, +} g_MobTypeNames[] = { + {mtBat, "bat", "Bat", "bat"}, + {mtBlaze, "blaze", "Blaze", "blaze"}, + {mtCaveSpider, "cavespider", "CaveSpider", "cave_spider"}, + {mtChicken, "chicken", "Chicken", "chicken"}, + {mtCow, "cow", "Cow", "cow"}, + {mtCreeper, "creeper", "Creeper", "creeper"}, + {mtEnderman, "enderman", "Enderman", "enderman"}, + {mtEndermite, "endermite", "Endermite", "endermite"}, + {mtEnderDragon, "enderdragon", "EnderDragon", "ender_dragon"}, + {mtGhast, "ghast", "Ghast", "ghast"}, + {mtGiant, "giant", "Giant", "giant"}, + {mtGuardian, "guardian", "Guardian", "guardian"}, + {mtHorse, "horse", "EntityHorse", "horse"}, + {mtIronGolem, "irongolem", "VillagerGolem", "iron_golem"}, + {mtMagmaCube, "magmacube", "LavaSlime", "magma_cube"}, + {mtMooshroom, "mooshroom", "MushroomCow", "mooshroom"}, + {mtOcelot, "ocelot", "Ozelot", "ocelot"}, + {mtPig, "pig", "Pig", "pig"}, + {mtRabbit, "rabbit", "Rabbit", "rabbit"}, + {mtSheep, "sheep", "Sheep", "sheep"}, + {mtSilverfish, "silverfish", "Silverfish", "silverfish"}, + {mtSkeleton, "skeleton", "Skeleton", "skeleton"}, + {mtSlime, "slime", "Slime", "slime"}, + {mtSnowGolem, "snowgolem", "SnowMan", "snow_golem"}, + {mtSpider, "spider", "Spider", "spider"}, + {mtSquid, "squid", "Squid", "squid"}, + {mtVillager, "villager", "Villager", "villager"}, + {mtWitch, "witch", "Witch", "witch"}, + {mtWither, "wither", "WitherBoss", "wither"}, {mtWitherSkeleton, "witherskeleton", "WitherSkeleton", "wither_skeleton"}, - {mtWolf, "wolf", "Wolf", "wolf"}, - {mtZombie, "zombie", "Zombie", "zombie"}, - {mtZombiePigman, "zombiepigman", "PigZombie", "zombie_pigman"}, + {mtWolf, "wolf", "Wolf", "wolf"}, + {mtZombie, "zombie", "Zombie", "zombie"}, + {mtZombiePigman, "zombiepigman", "PigZombie", "zombie_pigman"}, {mtZombieVillager, "zombievillager", "ZombieVillager", "zombie_villager"}, -} ; +}; @@ -81,47 +80,56 @@ static const struct //////////////////////////////////////////////////////////////////////////////// // cMonster: -cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, const AString & a_SoundAmbient, float a_Width, float a_Height) - : Super(etMonster, a_Width, a_Height) - , m_EMState(IDLE) - , m_EMPersonality(AGGRESSIVE) - , m_PathFinder(a_Width, a_Height) - , m_PathfinderActivated(false) - , m_JumpCoolDown(0) - , m_IdleInterval(0) - , m_DestroyTimer(0) - , m_MobType(a_MobType) - , m_CustomName() - , m_CustomNameAlwaysVisible(false) - , m_SoundHurt(a_SoundHurt) - , m_SoundDeath(a_SoundDeath) - , m_SoundAmbient(a_SoundAmbient) - , m_AttackRate(3) - , m_AttackDamage(1) - , m_AttackRange(1) - , m_AttackCoolDownTicksLeft(0) - , m_SightDistance(25) - , m_DropChanceWeapon(0.085f) - , m_DropChanceHelmet(0.085f) - , m_DropChanceChestplate(0.085f) - , m_DropChanceLeggings(0.085f) - , m_DropChanceBoots(0.085f) - , m_CanPickUpLoot(true) - , m_TicksSinceLastDamaged(100) - , m_BurnsInDaylight(false) - , m_RelativeWalkSpeed(1) - , m_Age(1) - , m_AgingTimer(TPS * 60 * 20) // about 20 minutes - , m_WasLastTargetAPlayer(false) - , m_LeashedTo(nullptr) - , m_LeashToPos(nullptr) - , m_IsLeashActionJustDone(false) - , m_CanBeLeashed(GetMobFamily() == eFamily::mfPassive) - , m_LovePartner(nullptr) - , m_LoveTimer(0) - , m_LoveCooldown(0) - , m_MatingTimer(0) - , m_Target(nullptr) +cMonster::cMonster( + const AString & a_ConfigName, + eMonsterType a_MobType, + const AString & a_SoundHurt, + const AString & a_SoundDeath, + const AString & a_SoundAmbient, + float a_Width, + float a_Height +) : + Super(etMonster, a_Width, a_Height), + m_EMState(IDLE), + m_EMPersonality(AGGRESSIVE), + m_PathFinder(a_Width, a_Height), + m_PathfinderActivated(false), + m_JumpCoolDown(0), + m_IdleInterval(0), + m_DestroyTimer(0), + m_MobType(a_MobType), + m_CustomName(), + m_CustomNameAlwaysVisible(false), + m_SoundHurt(a_SoundHurt), + m_SoundDeath(a_SoundDeath), + m_SoundAmbient(a_SoundAmbient), + m_AttackRate(3), + m_AttackDamage(1), + m_AttackRange(1), + m_AttackCoolDownTicksLeft(0), + m_SightDistance(25), + m_DropChanceWeapon(0.085f), + m_DropChanceHelmet(0.085f), + m_DropChanceChestplate(0.085f), + m_DropChanceLeggings(0.085f), + m_DropChanceBoots(0.085f), + m_CanPickUpLoot(true), + m_TicksSinceLastDamaged(100), + m_BurnsInDaylight(false), + m_RelativeWalkSpeed(1), + m_Age(1), + m_AgingTimer(TPS * 60 * 20) // about 20 minutes + , + m_WasLastTargetAPlayer(false), + m_LeashedTo(nullptr), + m_LeashToPos(nullptr), + m_IsLeashActionJustDone(false), + m_CanBeLeashed(GetMobFamily() == eFamily::mfPassive), + m_LovePartner(nullptr), + m_LoveTimer(0), + m_LoveCooldown(0), + m_MatingTimer(0), + m_Target(nullptr) { if (!a_ConfigName.empty()) { @@ -189,17 +197,18 @@ void cMonster::MoveToWayPoint(cChunk & a_Chunk) { if (DoesPosYRequireJump(FloorC(m_NextWayPointPosition.y))) { - if ( - (IsOnGround() && (GetSpeed().SqrLength() <= 0.5)) || // If walking on the ground, we need to slow down first, otherwise we miss the jump - IsInWater() - ) + if ((IsOnGround() && (GetSpeed().SqrLength() <= 0.5) + ) || // If walking on the ground, we need to slow down first, otherwise we miss the jump + IsInWater()) { m_bOnGround = false; m_JumpCoolDown = 20; AddPosY(1.6); // Jump!! SetSpeedY(1); SetSpeedX(3.2 * (m_NextWayPointPosition.x - GetPosition().x)); // Move forward in a preset speed. - SetSpeedZ(3.2 * (m_NextWayPointPosition.z - GetPosition().z)); // The numbers were picked based on trial and error + SetSpeedZ( + 3.2 * (m_NextWayPointPosition.z - GetPosition().z) + ); // The numbers were picked based on trial and error } } } @@ -297,7 +306,9 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) HandleDaylightBurning(*Chunk, WouldBurnAt(GetPosition(), *Chunk)); bool a_IsFollowingPath = false; - if (m_PathfinderActivated && (GetMobType() != mtGhast)) // Pathfinder is currently disabled for ghasts, which have their own flying mechanism + if (m_PathfinderActivated && + (GetMobType() != mtGhast + )) // Pathfinder is currently disabled for ghasts, which have their own flying mechanism { if (ReachedFinalDestination() || (m_LeashToPos != nullptr)) { @@ -306,21 +317,26 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) else { // Note that m_NextWayPointPosition is actually returned by GetNextWayPoint) - switch (m_PathFinder.GetNextWayPoint(*Chunk, GetPosition(), &m_FinalDestination, &m_NextWayPointPosition, m_EMState == IDLE)) + switch (m_PathFinder.GetNextWayPoint( + *Chunk, + GetPosition(), + &m_FinalDestination, + &m_NextWayPointPosition, + m_EMState == IDLE + )) { case ePathFinderStatus::PATH_FOUND: { - /* If I burn in daylight, and I won't burn where I'm standing, and I'll burn in my next position, and at least one of those is true: + /* If I burn in daylight, and I won't burn where I'm standing, and I'll burn in my next position, + and at least one of those is true: 1. I am idle 2. I was not hurt by a player recently. Then STOP. */ - if ( - m_BurnsInDaylight && ((m_TicksSinceLastDamaged >= 100) || (m_EMState == IDLE)) && - WouldBurnAt(m_NextWayPointPosition, *Chunk) && - !WouldBurnAt(GetPosition(), *Chunk) - ) + if (m_BurnsInDaylight && ((m_TicksSinceLastDamaged >= 100) || (m_EMState == IDLE)) && + WouldBurnAt(m_NextWayPointPosition, *Chunk) && !WouldBurnAt(GetPosition(), *Chunk)) { - // If we burn in daylight, and we would burn at the next step, and we won't burn where we are right now, and we weren't provoked recently: + // If we burn in daylight, and we would burn at the next step, and we won't burn where we are + // right now, and we weren't provoked recently: StopMovingToPosition(); } else @@ -337,7 +353,6 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } default: { - } } } @@ -402,11 +417,15 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) void cMonster::CalcLeashActions(std::chrono::milliseconds a_Dt) { - // This mob just spotted in the world and [m_LeashToPos not null] shows that should be leashed to a leash knot at m_LeashToPos. - // This keeps trying until knot is found. Leash knot may be in a different chunk that needn't or can't be loaded yet. + // This mob just spotted in the world and [m_LeashToPos not null] shows that should be leashed to a leash knot at + // m_LeashToPos. This keeps trying until knot is found. Leash knot may be in a different chunk that needn't or can't + // be loaded yet. if (!IsLeashed() && (m_LeashToPos != nullptr)) { - auto LeashKnot = cLeashKnot::FindKnotAtPos(*m_World, { FloorC(m_LeashToPos->x), FloorC(m_LeashToPos->y), FloorC(m_LeashToPos->z) }); + auto LeashKnot = cLeashKnot::FindKnotAtPos( + *m_World, + {FloorC(m_LeashToPos->x), FloorC(m_LeashToPos->y), FloorC(m_LeashToPos->z)} + ); if (LeashKnot != nullptr) { LeashTo(*LeashKnot); @@ -419,9 +438,9 @@ void cMonster::CalcLeashActions(std::chrono::milliseconds a_Dt) return; } - static const double CloseFollowDistance = 1.8; // The closest the mob will path towards the leashed to entity - static const double LeashNaturalLength = 5.0; // The closest the mob is actively pulled towards the entity - static const double LeashMaximumLength = 10.0; // Length where the leash breaks + static const double CloseFollowDistance = 1.8; // The closest the mob will path towards the leashed to entity + static const double LeashNaturalLength = 5.0; // The closest the mob is actively pulled towards the entity + static const double LeashMaximumLength = 10.0; // Length where the leash breaks static const double LeashSpringConstant = 20.0; // How stiff the leash is const auto LeashedToPos = m_LeashedTo->GetPosition(); @@ -460,7 +479,7 @@ void cMonster::CalcLeashActions(std::chrono::milliseconds a_Dt) { const Vector3d TargetBlock((LeashedToPos - Direction * CloseFollowDistance).Floor()); // Move to centre of target block face - MoveToPosition(TargetBlock + Vector3d{ 0.5, 0.0, 0.5 }); + MoveToPosition(TargetBlock + Vector3d {0.5, 0.0, 0.5}); } } @@ -583,12 +602,9 @@ bool cMonster::DoTakeDamage(TakeDamageInfo & a_TDI) if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPawn()) { - if ( - (!a_TDI.Attacker->IsPlayer()) || - (static_cast<cPlayer *>(a_TDI.Attacker)->CanMobsTarget()) - ) + if ((!a_TDI.Attacker->IsPlayer()) || (static_cast<cPlayer *>(a_TDI.Attacker)->CanMobsTarget())) { - SetTarget(static_cast<cPawn*>(a_TDI.Attacker)); + SetTarget(static_cast<cPawn *>(a_TDI.Attacker)); } m_TicksSinceLastDamaged = 0; } @@ -716,7 +732,8 @@ void cMonster::OnRightClicked(cPlayer & a_Player) } else if (IsLeashed()) { - // Mob is already leashed but client anticipates the server action and draws a leash link, so we need to send current leash to cancel it + // Mob is already leashed but client anticipates the server action and draws a leash link, so we need to send + // current leash to cancel it m_World->BroadcastLeashEntity(*this, *this->GetLeashedTo()); } else if (CanBeLeashed() && (EquippedItem.m_ItemType == E_ITEM_LEASH)) @@ -747,28 +764,33 @@ void cMonster::CheckEventSeePlayer(cChunk & a_Chunk) const auto MyHeadPosition = GetPosition().addedY(GetHeight()); // Enumerate all players within sight: - m_World->ForEachPlayer([this, &TargetPlayer, &ClosestDistance, MyHeadPosition](cPlayer & a_Player) - { - if (!a_Player.CanMobsTarget()) + m_World->ForEachPlayer( + [this, &TargetPlayer, &ClosestDistance, MyHeadPosition](cPlayer & a_Player) { - return false; - } + if (!a_Player.CanMobsTarget()) + { + return false; + } - const auto TargetHeadPosition = a_Player.GetPosition().addedY(a_Player.GetHeight()); - const auto TargetDistance = (TargetHeadPosition - MyHeadPosition).SqrLength(); + const auto TargetHeadPosition = a_Player.GetPosition().addedY(a_Player.GetHeight()); + const auto TargetDistance = (TargetHeadPosition - MyHeadPosition).SqrLength(); + + // TODO: Currently all mobs see through lava, but only Nether-native mobs should be able to. + if ((TargetDistance < ClosestDistance) && + cLineBlockTracer::LineOfSightTrace( + *GetWorld(), + MyHeadPosition, + TargetHeadPosition, + cLineBlockTracer::losAirWaterLava + )) + { + TargetPlayer = &a_Player; + ClosestDistance = TargetDistance; + } - // TODO: Currently all mobs see through lava, but only Nether-native mobs should be able to. - if ( - (TargetDistance < ClosestDistance) && - cLineBlockTracer::LineOfSightTrace(*GetWorld(), MyHeadPosition, TargetHeadPosition, cLineBlockTracer::losAirWaterLava) - ) - { - TargetPlayer = &a_Player; - ClosestDistance = TargetDistance; + return false; } - - return false; - }); + ); // Target him if suitable player found: if (TargetPlayer != nullptr) @@ -798,7 +820,7 @@ void cMonster::CheckEventLostPlayer(const std::chrono::milliseconds a_Dt) } // Check if the target is too far away: - if (!Target->GetBoundingBox().DoesIntersect({ GetPosition(), m_SightDistance * 2.0 })) + if (!Target->GetBoundingBox().DoesIntersect({GetPosition(), m_SightDistance * 2.0})) { EventLosePlayer(); return; @@ -806,7 +828,12 @@ void cMonster::CheckEventLostPlayer(const std::chrono::milliseconds a_Dt) const auto MyHeadPosition = GetPosition().addedY(GetHeight()); const auto TargetHeadPosition = Target->GetPosition().addedY(Target->GetHeight()); - if (!cLineBlockTracer::LineOfSightTrace(*GetWorld(), MyHeadPosition, TargetHeadPosition, cLineBlockTracer::losAirWaterLava)) + if (!cLineBlockTracer::LineOfSightTrace( + *GetWorld(), + MyHeadPosition, + TargetHeadPosition, + cLineBlockTracer::losAirWaterLava + )) { if ((m_LoseSightAbandonTargetTimer += a_Dt) > std::chrono::seconds(4)) { @@ -815,7 +842,8 @@ void cMonster::CheckEventLostPlayer(const std::chrono::milliseconds a_Dt) } else { - // Subtract the amount of time we "handled" instead of setting to zero, so we don't ignore a large a_Dt of say, 8s: + // Subtract the amount of time we "handled" instead of setting to zero, so we don't ignore a large a_Dt of say, + // 8s: m_LoseSightAbandonTargetTimer -= std::min(std::chrono::milliseconds(4000), m_LoseSightAbandonTargetTimer); } } @@ -869,7 +897,7 @@ void cMonster::InStateIdle(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Dist.x = static_cast<double>(Random.RandInt(-5, 5)); Dist.z = static_cast<double>(Random.RandInt(-5, 5)); - if ((Dist.SqrLength() > 2) && (rem >= 3)) + if ((Dist.SqrLength() > 2) && (rem >= 3)) { Vector3d Destination(GetPosX() + Dist.x, GetPosition().y, GetPosZ() + Dist.z); @@ -920,8 +948,10 @@ void cMonster::InStateEscaping(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) if (GetTarget() != nullptr) { Vector3d newloc = GetPosition(); - newloc.x = (GetTarget()->GetPosition().x < newloc.x)? (newloc.x + m_SightDistance): (newloc.x - m_SightDistance); - newloc.z = (GetTarget()->GetPosition().z < newloc.z)? (newloc.z + m_SightDistance): (newloc.z - m_SightDistance); + newloc.x = + (GetTarget()->GetPosition().x < newloc.x) ? (newloc.x + m_SightDistance) : (newloc.x - m_SightDistance); + newloc.z = + (GetTarget()->GetPosition().z < newloc.z) ? (newloc.z + m_SightDistance) : (newloc.z - m_SightDistance); MoveToPosition(newloc); } else @@ -936,7 +966,8 @@ void cMonster::InStateEscaping(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) void cMonster::ResetAttackCooldown() { - m_AttackCoolDownTicksLeft = static_cast<int>(TPS * m_AttackRate); // A second has 20 ticks, an attack rate of 1 means 1 hit every second + m_AttackCoolDownTicksLeft = + static_cast<int>(TPS * m_AttackRate); // A second has 20 ticks, an attack rate of 1 means 1 hit every second } @@ -1105,26 +1136,28 @@ cMonster::eFamily cMonster::FamilyFromType(eMonsterType a_Type) switch (a_Type) { - case mtBat: return mfAmbient; - case mtBlaze: return mfHostile; - case mtCat: return mfPassive; - case mtCaveSpider: return mfHostile; - case mtChicken: return mfPassive; - case mtCod: return mfWater; - case mtCow: return mfPassive; - case mtCreeper: return mfHostile; - case mtDolphin: return mfWater; - case mtDonkey: return mfPassive; - case mtDrowned: return mfHostile; - case mtElderGuardian: return mfHostile; - case mtEnderDragon: return mfNoSpawn; - case mtEnderman: return mfHostile; - case mtEndermite: return mfHostile; - case mtEvoker: return mfHostile; - case mtFox: return mfPassive; - case mtGhast: return mfHostile; - case mtGiant: return mfNoSpawn; - case mtGuardian: return mfWater; // Just because they have special spawning conditions. TODO: If Watertemples have been added, this needs to be edited! + case mtBat: return mfAmbient; + case mtBlaze: return mfHostile; + case mtCat: return mfPassive; + case mtCaveSpider: return mfHostile; + case mtChicken: return mfPassive; + case mtCod: return mfWater; + case mtCow: return mfPassive; + case mtCreeper: return mfHostile; + case mtDolphin: return mfWater; + case mtDonkey: return mfPassive; + case mtDrowned: return mfHostile; + case mtElderGuardian: return mfHostile; + case mtEnderDragon: return mfNoSpawn; + case mtEnderman: return mfHostile; + case mtEndermite: return mfHostile; + case mtEvoker: return mfHostile; + case mtFox: return mfPassive; + case mtGhast: return mfHostile; + case mtGiant: return mfNoSpawn; + case mtGuardian: + return mfWater; // Just because they have special spawning conditions. TODO: If Watertemples have been + // added, this needs to be edited! case mtHoglin: return mfHostile; case mtHorse: return mfPassive; case mtHusk: return mfHostile; @@ -1187,11 +1220,11 @@ cTickTime cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily) { switch (a_MobFamily) { - case mfHostile: return 40_tick; - case mfPassive: return 40_tick; - case mfAmbient: return 40_tick; - case mfWater: return 400_tick; - case mfNoSpawn: return -1_tick; + case mfHostile: return 40_tick; + case mfPassive: return 40_tick; + case mfAmbient: return 40_tick; + case mfWater: return 400_tick; + case mfNoSpawn: return -1_tick; } UNREACHABLE("Unhandled mob family"); } @@ -1201,7 +1234,7 @@ cTickTime cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily) /** Sets the target. */ -void cMonster::SetTarget (cPawn * a_NewTarget) +void cMonster::SetTarget(cPawn * a_NewTarget) { ASSERT((a_NewTarget == nullptr) || (IsTicking())); if (m_Target == a_NewTarget) @@ -1224,7 +1257,6 @@ void cMonster::SetTarget (cPawn * a_NewTarget) m_Target->TargetingMe(this); m_WasLastTargetAPlayer = m_Target->IsPlayer(); } - } @@ -1326,7 +1358,7 @@ std::unique_ptr<cMonster> cMonster::NewMonsterFromType(eMonsterType a_MobType) -void cMonster::EngageLoveMode(cMonster *a_Partner) +void cMonster::EngageLoveMode(cMonster * a_Partner) { m_LovePartner = a_Partner; m_MatingTimer = 50; // about 3 seconds of mating @@ -1343,7 +1375,8 @@ void cMonster::ResetLoveMode() m_MatingTimer = 0; m_LoveCooldown = TPS * 60 * 5; // 5 minutes - // when an animal is in love mode, the client only stops sending the hearts if we let them know it's in cooldown, which is done with the "age" metadata + // when an animal is in love mode, the client only stops sending the hearts if we let them know it's in cooldown, + // which is done with the "age" metadata m_World->BroadcastEntityMetadata(*this); } @@ -1371,11 +1404,14 @@ void cMonster::LoveTick(void) cMonster * Baby = nullptr; - m_World->DoWithEntityByID(BabyID, [&](cEntity & a_Entity) - { - Baby = static_cast<cMonster *>(&a_Entity); - return true; - }); + m_World->DoWithEntityByID( + BabyID, + [&](cEntity & a_Entity) + { + Baby = static_cast<cMonster *>(&a_Entity); + return true; + } + ); if (Baby != nullptr) { @@ -1384,15 +1420,18 @@ void cMonster::LoveTick(void) m_World->SpawnExperienceOrb(Pos.x, Pos.y, Pos.z, GetRandomProvider().RandInt(1, 6)); - m_World->DoWithPlayerByUUID(m_Feeder, [&] (cPlayer & a_Player) - { - a_Player.GetStatistics().Custom[CustomStatistic::AnimalsBred]++; - if (GetMobType() == eMonsterType::mtCow) + m_World->DoWithPlayerByUUID( + m_Feeder, + [&](cPlayer & a_Player) { - a_Player.AwardAchievement(CustomStatistic::AchBreedCow); + a_Player.GetStatistics().Custom[CustomStatistic::AnimalsBred]++; + if (GetMobType() == eMonsterType::mtCow) + { + a_Player.AwardAchievement(CustomStatistic::AchBreedCow); + } + return true; } - return true; - }); + ); m_LovePartner->ResetLoveMode(); ResetLoveMode(); } @@ -1404,17 +1443,21 @@ void cMonster::LoveTick(void) GetFollowedItems(FollowedItems); if (FollowedItems.Size() > 0) { - m_World->DoWithNearestPlayer(GetPosition(), static_cast<float>(m_SightDistance), [&](cPlayer & a_Player) -> bool - { - const cItem & EquippedItem = a_Player.GetEquippedItem(); - if (FollowedItems.ContainsType(EquippedItem)) + m_World->DoWithNearestPlayer( + GetPosition(), + static_cast<float>(m_SightDistance), + [&](cPlayer & a_Player) -> bool { - Vector3d PlayerPos = a_Player.GetPosition(); - MoveToPosition(PlayerPos); - } + const cItem & EquippedItem = a_Player.GetEquippedItem(); + if (FollowedItems.ContainsType(EquippedItem)) + { + Vector3d PlayerPos = a_Player.GetPosition(); + MoveToPosition(PlayerPos); + } - return true; - }); + return true; + } + ); } } @@ -1423,36 +1466,39 @@ void cMonster::LoveTick(void) { if (m_LovePartner == nullptr) { - m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), 8, 8), [=](cEntity & a_Entity) - { - // If the entity is not a monster, don't breed with it - // Also, do not self-breed - if ((a_Entity.GetEntityType() != etMonster) || (&a_Entity == this)) + m_World->ForEachEntityInBox( + cBoundingBox(GetPosition(), 8, 8), + [=](cEntity & a_Entity) { - return false; - } + // If the entity is not a monster, don't breed with it + // Also, do not self-breed + if ((a_Entity.GetEntityType() != etMonster) || (&a_Entity == this)) + { + return false; + } - auto & Me = static_cast<cMonster &>(*this); - auto & PotentialPartner = static_cast<cMonster &>(a_Entity); + auto & Me = static_cast<cMonster &>(*this); + auto & PotentialPartner = static_cast<cMonster &>(a_Entity); - // If the potential partner is not of the same species, don't breed with it - if (PotentialPartner.GetMobType() != Me.GetMobType()) - { - return false; - } + // If the potential partner is not of the same species, don't breed with it + if (PotentialPartner.GetMobType() != Me.GetMobType()) + { + return false; + } - // If the potential partner is not in love - // Or they already have a mate, do not breed with them - if ((!PotentialPartner.IsInLove()) || (PotentialPartner.GetPartner() != nullptr)) - { - return false; - } + // If the potential partner is not in love + // Or they already have a mate, do not breed with them + if ((!PotentialPartner.IsInLove()) || (PotentialPartner.GetPartner() != nullptr)) + { + return false; + } - // All conditions met, let's breed! - PotentialPartner.EngageLoveMode(&Me); - Me.EngageLoveMode(&PotentialPartner); - return true; - }); + // All conditions met, let's breed! + PotentialPartner.EngageLoveMode(&Me); + Me.EngageLoveMode(&PotentialPartner); + return true; + } + ); } m_LoveTimer--; @@ -1495,10 +1541,10 @@ void cMonster::RightClickFeed(cPlayer & a_Player) if (EquippedItem.m_ItemType == E_ITEM_SPAWN_EGG) { eMonsterType MonsterType = cItemSpawnEggHandler::ItemDamageToMonsterType(EquippedItem.m_ItemDamage); - if ( - (MonsterType == m_MobType) && - (m_World->SpawnMob(GetPosX(), GetPosY(), GetPosZ(), m_MobType, true) != cEntity::INVALID_ID) // Spawning succeeded - ) + if ((MonsterType == m_MobType) && + (m_World->SpawnMob(GetPosX(), GetPosY(), GetPosZ(), m_MobType, true) != cEntity::INVALID_ID + ) // Spawning succeeded + ) { if (!a_Player.IsGameModeCreative()) { @@ -1515,7 +1561,13 @@ void cMonster::RightClickFeed(cPlayer & a_Player) -void cMonster::AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth) +void cMonster::AddRandomDropItem( + cItems & a_Drops, + unsigned int a_Min, + unsigned int a_Max, + short a_Item, + short a_ItemHealth +) { auto Count = GetRandomProvider().RandInt(a_Min, a_Max); auto MaxStackSize = static_cast<unsigned int>(cItem(a_Item).GetMaxStackSize()); @@ -1669,11 +1721,10 @@ bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk) return false; } - if ( - (Chunk->GetBlock(Rel) != E_BLOCK_SOULSAND) && // Not on soulsand - (GetWorld()->GetTimeOfDay() < 13000_tick) && // Daytime - Chunk->IsWeatherSunnyAt(Rel.x, Rel.z) && // Not raining - !IsInWater() // Isn't swimming + if ((Chunk->GetBlock(Rel) != E_BLOCK_SOULSAND) && // Not on soulsand + (GetWorld()->GetTimeOfDay() < 13000_tick) && // Daytime + Chunk->IsWeatherSunnyAt(Rel.x, Rel.z) && // Not raining + !IsInWater() // Isn't swimming ) { int MobHeight = CeilC(a_Location.y + GetHeight()) - 1; // The block Y coord of the mob's head @@ -1683,8 +1734,8 @@ bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk) } // Start with the highest block and scan down to just above the mob's head. // If a non transparent is found, return false (do not burn). Otherwise return true. - // Note that this loop is not a performance concern as transparent blocks are rare and the loop almost always bailes out - // instantly.(An exception is e.g. standing under a long column of glass). + // Note that this loop is not a performance concern as transparent blocks are rare and the loop almost always + // bailes out instantly.(An exception is e.g. standing under a long column of glass). int CurrentBlock = Chunk->GetHeight(Rel.x, Rel.z); while (CurrentBlock > MobHeight) { @@ -1702,7 +1753,6 @@ bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk) --CurrentBlock; } return true; - } return false; } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 0127ec4ce..c3b513682 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -13,8 +13,7 @@ class cClientHandle; // tolua_begin -class cMonster: - public cPawn +class cMonster : public cPawn { // tolua_end @@ -23,29 +22,47 @@ class cMonster: // tolua_begin -public: - + public: enum eFamily { - mfHostile = 0, // Spider, Zombies ... - mfPassive = 1, // Cows, Pigs - mfAmbient = 2, // Bats - mfWater = 3, // Squid, Guardian + mfHostile = 0, // Spider, Zombies ... + mfPassive = 1, // Cows, Pigs + mfAmbient = 2, // Bats + mfWater = 3, // Squid, Guardian mfNoSpawn - } ; + }; // tolua_end - enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState; - enum MPersonality{PASSIVE, AGGRESSIVE, COWARDLY} m_EMPersonality; + enum MState + { + ATTACKING, + IDLE, + CHASING, + ESCAPING + } m_EMState; + enum MPersonality + { + PASSIVE, + AGGRESSIVE, + COWARDLY + } m_EMPersonality; /** Creates the mob object. If a_ConfigName is not empty, the configuration is loaded using GetMonsterConfig() a_MobType is the type of the mob (also used in the protocol ( http://wiki.vg/Entities#Mobs 2012_12_22)) a_SoundHurt and a_SoundDeath are assigned into m_SoundHurt and m_SoundDeath, respectively */ - cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, const AString & a_SoundAmbient, float a_Width, float a_Height); + cMonster( + const AString & a_ConfigName, + eMonsterType a_MobType, + const AString & a_SoundHurt, + const AString & a_SoundDeath, + const AString & a_SoundAmbient, + float a_Width, + float a_Height + ); CLASS_PROTODEF(cMonster) @@ -118,8 +135,8 @@ public: virtual void EventLosePlayer(void); virtual void CheckEventLostPlayer(std::chrono::milliseconds a_Dt); - virtual void InStateIdle (std::chrono::milliseconds a_Dt, cChunk & a_Chunk); - virtual void InStateChasing (std::chrono::milliseconds a_Dt, cChunk & a_Chunk); + virtual void InStateIdle(std::chrono::milliseconds a_Dt, cChunk & a_Chunk); + virtual void InStateChasing(std::chrono::milliseconds a_Dt, cChunk & a_Chunk); virtual void InStateEscaping(std::chrono::milliseconds a_Dt, cChunk & a_Chunk); double GetAttackRate() { return m_AttackRate; } @@ -149,13 +166,13 @@ public: void SetRelativeWalkSpeed(double a_WalkSpeed) { m_RelativeWalkSpeed = a_WalkSpeed; } // tolua_export // Overridables to handle ageable mobs - virtual bool IsTame (void) const { return false; } - virtual bool IsSitting (void) const { return false; } + virtual bool IsTame(void) const { return false; } + virtual bool IsSitting(void) const { return false; } // tolua_begin - bool IsBaby (void) const { return m_Age < 0; } - int GetAge (void) const { return m_Age; } - void SetAge(int a_Age) { m_Age = a_Age; } + bool IsBaby(void) const { return m_Age < 0; } + int GetAge(void) const { return m_Age; } + void SetAge(int a_Age) { m_Age = a_Age; } // tolua_end @@ -199,7 +216,7 @@ public: static AString MobTypeToVanillaNBT(eMonsterType a_MobType); /** Sets the target that this mob will chase. Pass a nullptr to unset. */ - void SetTarget (cPawn * a_NewTarget); + void SetTarget(cPawn * a_NewTarget); /** Unset the target without notifying the target entity. Do not use this, use SetTarget(nullptr) instead. This is only used by cPawn internally. */ @@ -220,24 +237,28 @@ public: /* the breeding processing */ /** Returns the items that the animal of this class follows when a player holds it in hand. */ - virtual void GetFollowedItems(cItems & a_Items) { } + virtual void GetFollowedItems(cItems & a_Items) {} - /** Returns the items that make the animal breed - this is usually the same as the ones that make the animal follow, but not necessarily. */ + /** Returns the items that make the animal breed - this is usually the same as the ones that make the animal follow, + * but not necessarily. */ virtual void GetBreedingItems(cItems & a_Items) { GetFollowedItems(a_Items); } /** Called after the baby is born, allows the baby to inherit the parents' properties (color, etc.) */ - virtual void InheritFromParents(cMonster * a_Parent1, cMonster * a_Parent2) { } + virtual void InheritFromParents(cMonster * a_Parent1, cMonster * a_Parent2) {} /** Returns the partner which the monster is currently mating with. */ cMonster * GetPartner(void) const { return m_LovePartner; } - /** Start the mating process. Causes the monster to keep bumping into the partner until m_MatingTimer reaches zero. */ + /** Start the mating process. Causes the monster to keep bumping into the partner until m_MatingTimer reaches zero. + */ void EngageLoveMode(cMonster * a_Partner); - /** Finish the mating process. Called after a baby is born. Resets all breeding related timers and sets m_LoveCooldown to 20 minutes. */ + /** Finish the mating process. Called after a baby is born. Resets all breeding related timers and sets + * m_LoveCooldown to 20 minutes. */ void ResetLoveMode(); - /** Returns whether the monster has just been fed and is ready to mate. If this is "true" and GetPartner isn't "nullptr", then the monster is mating. */ + /** Returns whether the monster has just been fed and is ready to mate. If this is "true" and GetPartner isn't + * "nullptr", then the monster is mating. */ bool IsInLove() const { return (m_LoveTimer > 0); } /** Returns whether the monster is tired of breeding and is in the cooldown state. */ @@ -249,12 +270,12 @@ public: /** Right click call to process feeding */ void RightClickFeed(cPlayer & a_Player); -protected: - + protected: /** The pathfinder instance handles pathfinding for this monster. */ cPathFinder m_PathFinder; - /** Stores if pathfinder is being used - set when final destination is set, and unset when stopped moving to final destination */ + /** Stores if pathfinder is being used - set when final destination is set, and unset when stopped moving to final + * destination */ bool m_PathfinderActivated; /** Coordinates of the next position that should be reached */ @@ -270,7 +291,10 @@ protected: int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ); /** Returns if the ultimate, final destination has been reached. */ - bool ReachedFinalDestination(void) { return ((m_FinalDestination - GetPosition()).SqrLength() < WAYPOINT_RADIUS * WAYPOINT_RADIUS); } + bool ReachedFinalDestination(void) + { + return ((m_FinalDestination - GetPosition()).SqrLength() < WAYPOINT_RADIUS * WAYPOINT_RADIUS); + } /** Returns whether or not the target is close enough for attack. */ bool TargetIsInRange(void) @@ -337,7 +361,8 @@ protected: /** Entity leashed to */ cEntity * m_LeashedTo; - /** Entity pos where this mob was leashed to. Used when deserializing the chunk in order to make the mob find the leash knot. */ + /** Entity pos where this mob was leashed to. Used when deserializing the chunk in order to make the mob find the + * leash knot. */ std::unique_ptr<Vector3d> m_LeashToPos; /** Mob has ben leashed or unleashed in current player action. Avoids double actions on horses. */ @@ -347,18 +372,27 @@ protected: bool m_CanBeLeashed; /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops */ - void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); + void AddRandomDropItem( + cItems & a_Drops, + unsigned int a_Min, + unsigned int a_Max, + short a_Item, + short a_ItemHealth = 0 + ); /** Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops */ void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); - /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops */ + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or + * custom) to the itemdrop a_Drops */ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, unsigned int a_LootingLevel); - /** Adds armor that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if picked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop */ + /** Adds armor that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if picked up + * or 0.085 + (0.01 per LootingLevel) if born with) to the drop */ void AddRandomArmorDropItem(cItems & a_Drops, unsigned int a_LootingLevel); - /** Adds weapon that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if picked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop */ + /** Adds weapon that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if picked up + * or 0.085 + (0.01 per LootingLevel) if born with) to the drop */ void AddRandomWeaponDropItem(cItems & a_Drops, unsigned int a_LootingLevel); /* The breeding processing */ @@ -369,16 +403,19 @@ protected: /** Remembers the player is was last fed by for statistics tracking */ cUUID m_Feeder; - /** If above 0, the monster is in love mode, and will breed if a nearby monster is also in love mode. Decrements by 1 per tick till reaching zero. */ + /** If above 0, the monster is in love mode, and will breed if a nearby monster is also in love mode. Decrements by + * 1 per tick till reaching zero. */ int m_LoveTimer; - /** If above 0, the monster is in cooldown mode and will refuse to breed. Decrements by 1 per tick till reaching zero. */ + /** If above 0, the monster is in cooldown mode and will refuse to breed. Decrements by 1 per tick till reaching + * zero. */ int m_LoveCooldown; - /** The monster is engaged in mating, once this reaches zero, a baby will be born. Decrements by 1 per tick till reaching zero, then a baby is made and ResetLoveMode() is called. */ + /** The monster is engaged in mating, once this reaches zero, a baby will be born. Decrements by 1 per tick till + * reaching zero, then a baby is made and ResetLoveMode() is called. */ int m_MatingTimer; -private: + private: /** A pointer to the entity this mobile is aiming to reach. The validity of this pointer SHALL be guaranteed by the pointee; it MUST be reset when the pointee changes worlds or is destroyed. */ @@ -387,4 +424,4 @@ private: /** Leash calculations inside Tick function */ void CalcLeashActions(std::chrono::milliseconds a_Dt); -} ; // tolua_export +}; // tolua_export diff --git a/src/Mobs/MonsterTypes.h b/src/Mobs/MonsterTypes.h index 5a591b31f..31c05eb01 100644 --- a/src/Mobs/MonsterTypes.h +++ b/src/Mobs/MonsterTypes.h @@ -13,48 +13,48 @@ enum eMonsterType mtBat, mtBlaze, - mtCat, // Added in 1.14 + mtCat, // Added in 1.14 mtCaveSpider, mtChicken, - mtCod, // Added in 1.13 + mtCod, // Added in 1.13 mtCow, mtCreeper, - mtDolphin, // Added in 1.13 - mtDonkey, // Added in 1.6 - mtDrowned, // Added in 1.13 - mtElderGuardian, // Added in 1.13 + mtDolphin, // Added in 1.13 + mtDonkey, // Added in 1.6 + mtDrowned, // Added in 1.13 + mtElderGuardian, // Added in 1.13 mtEnderDragon, mtEnderman, - mtEndermite, // Added in 1.8 - mtEvoker, // Added in 1.11 - mtFox, // Added in 1.14 + mtEndermite, // Added in 1.8 + mtEvoker, // Added in 1.11 + mtFox, // Added in 1.14 mtGhast, mtGiant, mtGuardian, mtHorse, - mtHoglin, // Added in 1.16 - mtHusk, // Added in 1.10 - mtIllusioner, // Added in 1.12 + mtHoglin, // Added in 1.16 + mtHusk, // Added in 1.10 + mtIllusioner, // Added in 1.12 mtIronGolem, - mtLlama, // Added in 1.11 + mtLlama, // Added in 1.11 mtMagmaCube, mtMooshroom, - mtMule, // Added in 1.6 + mtMule, // Added in 1.6 mtOcelot, - mtPanda, // Added in 1.14 - mtParrot, // Added in 1.12 - mtPhantom, // Added in 1.13 + mtPanda, // Added in 1.14 + mtParrot, // Added in 1.12 + mtPhantom, // Added in 1.13 mtPig, - mtPiglin, // Added in 1.16 - mtPiglinBrute, // Added in 1.16 - mtPillager, // Added in 1.14 - mtPolarBear, // Added in 1.10 - mtPufferfish, // Added in 1.13 + mtPiglin, // Added in 1.16 + mtPiglinBrute, // Added in 1.16 + mtPillager, // Added in 1.14 + mtPolarBear, // Added in 1.10 + mtPufferfish, // Added in 1.13 mtRabbit, - mtRavager, // Added in 1.14 - mtSalmon, // Added in 1.13 + mtRavager, // Added in 1.14 + mtSalmon, // Added in 1.13 mtSheep, - mtShulker, // Added in 1.9 + mtShulker, // Added in 1.9 mtSilverfish, mtSkeleton, mtSkeletonHorse, @@ -62,27 +62,27 @@ enum eMonsterType mtSnowGolem, mtSpider, mtSquid, - mtStray, // Added in 1.10 - mtStrider, // Added in 1.16 - mtTraderLlama, // Added in 1.11 - mtTropicalFish, // Added in 1.13 - mtTurtle, // Added in 1.13 - mtVex, // Added in 1.11 + mtStray, // Added in 1.10 + mtStrider, // Added in 1.16 + mtTraderLlama, // Added in 1.11 + mtTropicalFish, // Added in 1.13 + mtTurtle, // Added in 1.13 + mtVex, // Added in 1.11 mtVillager, - mtVindicator, // Added in 1.11 - mtWanderingTrader, // Added in 1.14 + mtVindicator, // Added in 1.11 + mtWanderingTrader, // Added in 1.14 mtWitch, mtWither, mtWitherSkeleton, mtWolf, - mtZoglin, // Added in 1.16 + mtZoglin, // Added in 1.16 mtZombie, - mtZombieHorse, // Added in 1.6 + mtZombieHorse, // Added in 1.6 mtZombifiedPiglin, mtZombieVillager, // Synonyms: mtZombiePigman = mtZombifiedPiglin, -} ; +}; // tolua_end diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 35eb7f3d1..102e47943 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -48,7 +48,8 @@ void cMooshroom::OnRightClicked(cPlayer & a_Player) { a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_MILK)); } - } break; + } + break; case E_ITEM_BOWL: { // Soup the cow. @@ -56,7 +57,8 @@ void cMooshroom::OnRightClicked(cPlayer & a_Player) { a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_MUSHROOM_SOUP)); } - } break; + } + break; case E_ITEM_SHEARS: { if (!a_Player.IsGameModeCreative()) @@ -69,6 +71,7 @@ void cMooshroom::OnRightClicked(cPlayer & a_Player) m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); m_World->SpawnMob(GetPosX(), GetPosY(), GetPosZ(), mtCow, false); Destroy(); - } break; + } + break; } } diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h index 7ecd45c5b..8b4a7e02b 100644 --- a/src/Mobs/Mooshroom.h +++ b/src/Mobs/Mooshroom.h @@ -7,13 +7,11 @@ -class cMooshroom: - public cPassiveMonster +class cMooshroom : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: cMooshroom(); CLASS_PROTODEF(cMooshroom) @@ -21,12 +19,5 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual void OnRightClicked(cPlayer & a_Player) override; - virtual void GetFollowedItems(cItems & a_Items) override - { - a_Items.Add(E_ITEM_WHEAT); - } -} ; - - - - + virtual void GetFollowedItems(cItems & a_Items) override { a_Items.Add(E_ITEM_WHEAT); } +}; diff --git a/src/Mobs/Ocelot.cpp b/src/Mobs/Ocelot.cpp index a3c505e96..f3ad9ccaf 100644 --- a/src/Mobs/Ocelot.cpp +++ b/src/Mobs/Ocelot.cpp @@ -48,31 +48,36 @@ void cOcelot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_CheckPlayerTickCount == 23) { - m_World->DoWithNearestPlayer(GetPosition(), 10, [&](cPlayer & a_Player) -> bool - { - cItems Items; - GetBreedingItems(Items); - if (Items.ContainsType(a_Player.GetEquippedItem().m_ItemType)) + m_World->DoWithNearestPlayer( + GetPosition(), + 10, + [&](cPlayer & a_Player) -> bool { - if (!IsBegging()) + cItems Items; + GetBreedingItems(Items); + if (Items.ContainsType(a_Player.GetEquippedItem().m_ItemType)) { - SetIsBegging(true); - m_World->BroadcastEntityMetadata(*this); - } + if (!IsBegging()) + { + SetIsBegging(true); + m_World->BroadcastEntityMetadata(*this); + } - MoveToPosition(a_Player.GetPosition()); - } - else - { - if (IsBegging()) + MoveToPosition(a_Player.GetPosition()); + } + else { - SetIsBegging(false); - m_World->BroadcastEntityMetadata(*this); + if (IsBegging()) + { + SetIsBegging(false); + m_World->BroadcastEntityMetadata(*this); + } } - } - return true; - }, true); + return true; + }, + true + ); m_CheckPlayerTickCount = 0; } else @@ -142,10 +147,7 @@ void cOcelot::OnRightClicked(cPlayer & a_Player) { if (!IsTame()) { - if ( - IsBegging() && - ((a_Player.GetPosition() - GetPosition()).Length() <= 3) - ) + if (IsBegging() && ((a_Player.GetPosition() - GetPosition()).Length() <= 3)) { cItems Items; GetBreedingItems(Items); diff --git a/src/Mobs/Ocelot.h b/src/Mobs/Ocelot.h index 28deef4b4..ca91e8950 100644 --- a/src/Mobs/Ocelot.h +++ b/src/Mobs/Ocelot.h @@ -8,20 +8,18 @@ -class cOcelot: - public cPassiveMonster +class cOcelot : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: enum eCatType { ctWildOcelot, ctTuxedo, ctTabby, ctSiamese, - } ; + }; cOcelot(void); @@ -30,46 +28,38 @@ public: virtual void OnRightClicked(cPlayer & a_Player) override; virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void TickFollowPlayer(); - virtual void GetBreedingItems(cItems & a_Items) override - { - a_Items.Add(E_ITEM_RAW_FISH); - } + virtual void GetBreedingItems(cItems & a_Items) override { a_Items.Add(E_ITEM_RAW_FISH); } virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; // Get functions - bool IsSitting (void) const override { return m_IsSitting; } - bool IsTame (void) const override { return m_IsTame; } - bool IsBegging (void) const { return m_IsBegging; } - AString GetOwnerName (void) const { return m_OwnerName; } - cUUID GetOwnerUUID (void) const { return m_OwnerUUID; } - eCatType GetOcelotType (void) const { return m_CatType; } + bool IsSitting(void) const override { return m_IsSitting; } + bool IsTame(void) const override { return m_IsTame; } + bool IsBegging(void) const { return m_IsBegging; } + AString GetOwnerName(void) const { return m_OwnerName; } + cUUID GetOwnerUUID(void) const { return m_OwnerUUID; } + eCatType GetOcelotType(void) const { return m_CatType; } // Set functions - void SetIsSitting (bool a_IsSitting) { m_IsSitting = a_IsSitting; } - void SetIsTame (bool a_IsTame) { m_IsTame = a_IsTame; } - void SetIsBegging (bool a_IsBegging) { m_IsBegging = a_IsBegging; } - void SetOwner (const AString & a_NewOwnerName, const cUUID & a_NewOwnerUUID) + void SetIsSitting(bool a_IsSitting) { m_IsSitting = a_IsSitting; } + void SetIsTame(bool a_IsTame) { m_IsTame = a_IsTame; } + void SetIsBegging(bool a_IsBegging) { m_IsBegging = a_IsBegging; } + void SetOwner(const AString & a_NewOwnerName, const cUUID & a_NewOwnerUUID) { m_OwnerName = a_NewOwnerName; m_OwnerUUID = a_NewOwnerUUID; } - void SetCatType (eCatType a_CatType) { m_CatType = a_CatType; } + void SetCatType(eCatType a_CatType) { m_CatType = a_CatType; } /** Returns true if there's a cat sitting above the given position */ static bool IsCatSittingOnBlock(cWorld * a_World, Vector3d a_BlockPosition); -protected: - - bool m_IsSitting; - bool m_IsTame; - bool m_IsBegging; - eCatType m_CatType; + protected: + bool m_IsSitting; + bool m_IsTame; + bool m_IsBegging; + eCatType m_CatType; /** Only check for a nearby player holding the breeding items every 23 ticks. */ - int m_CheckPlayerTickCount; - AString m_OwnerName; - cUUID m_OwnerUUID; -} ; - - - - + int m_CheckPlayerTickCount; + AString m_OwnerName; + cUUID m_OwnerUUID; +}; diff --git a/src/Mobs/PassiveAggressiveMonster.cpp b/src/Mobs/PassiveAggressiveMonster.cpp index 16f8d7fdd..a74e393b9 100644 --- a/src/Mobs/PassiveAggressiveMonster.cpp +++ b/src/Mobs/PassiveAggressiveMonster.cpp @@ -9,7 +9,15 @@ -cPassiveAggressiveMonster::cPassiveAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, const AString & a_SoundAmbient, float a_Width, float a_Height) : +cPassiveAggressiveMonster::cPassiveAggressiveMonster( + const AString & a_ConfigName, + eMonsterType a_MobType, + const AString & a_SoundHurt, + const AString & a_SoundDeath, + const AString & a_SoundAmbient, + float a_Width, + float a_Height +) : Super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_SoundAmbient, a_Width, a_Height) { m_EMPersonality = PASSIVE; @@ -44,5 +52,3 @@ void cPassiveAggressiveMonster::EventSeePlayer(cPlayer *, cChunk & a_Chunk) { // don't do anything, neutral mobs don't react to just seeing the player } - - diff --git a/src/Mobs/PassiveAggressiveMonster.h b/src/Mobs/PassiveAggressiveMonster.h index 50ecdb0c2..ac186b940 100644 --- a/src/Mobs/PassiveAggressiveMonster.h +++ b/src/Mobs/PassiveAggressiveMonster.h @@ -7,13 +7,11 @@ -class cPassiveAggressiveMonster: - public cAggressiveMonster +class cPassiveAggressiveMonster : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cPassiveAggressiveMonster( const AString & a_ConfigName, eMonsterType a_MobType, @@ -26,8 +24,4 @@ public: virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void EventSeePlayer(cPlayer *, cChunk & a_Chunk) override; -} ; - - - - +}; diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index e86d7c87d..44b01714e 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -10,7 +10,15 @@ -cPassiveMonster::cPassiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, const AString & a_SoundAmbient, float a_Width, float a_Height) : +cPassiveMonster::cPassiveMonster( + const AString & a_ConfigName, + eMonsterType a_MobType, + const AString & a_SoundHurt, + const AString & a_SoundDeath, + const AString & a_SoundAmbient, + float a_Width, + float a_Height +) : Super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_SoundAmbient, a_Width, a_Height) { m_EMPersonality = PASSIVE; @@ -63,6 +71,3 @@ void cPassiveMonster::OnRightClicked(cPlayer & a_Player) Super::OnRightClicked(a_Player); Super::RightClickFeed(a_Player); } - - - diff --git a/src/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h index 283326904..619c50363 100644 --- a/src/Mobs/PassiveMonster.h +++ b/src/Mobs/PassiveMonster.h @@ -8,13 +8,11 @@ -class cPassiveMonster: - public cMonster +class cPassiveMonster : public cMonster { using Super = cMonster; -public: - + public: cPassiveMonster( const AString & a_ConfigName, eMonsterType a_MobType, diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp index 05ccd6c39..6dd2d4100 100644 --- a/src/Mobs/Path.cpp +++ b/src/Mobs/Path.cpp @@ -19,7 +19,7 @@ -bool compareHeuristics::operator()(cPathCell * & a_Cell1, cPathCell * & a_Cell2) +bool compareHeuristics::operator()(cPathCell *& a_Cell1, cPathCell *& a_Cell2) { return a_Cell1->m_F > a_Cell2->m_F; } @@ -31,12 +31,16 @@ bool compareHeuristics::operator()(cPathCell * & a_Cell1, cPathCell * & a_Cell2) /* cPath implementation */ cPath::cPath( cChunk & a_Chunk, - const Vector3d & a_StartingPoint, const Vector3d & a_EndingPoint, int a_MaxSteps, - double a_BoundingBoxWidth, double a_BoundingBoxHeight + const Vector3d & a_StartingPoint, + const Vector3d & a_EndingPoint, + int a_MaxSteps, + double a_BoundingBoxWidth, + double a_BoundingBoxHeight ) : m_StepsLeft(a_MaxSteps), m_IsValid(true), - m_CurrentPoint(0), // GetNextPoint increments this to 1, but that's fine, since the first cell is always a_StartingPoint + m_CurrentPoint(0 + ), // GetNextPoint increments this to 1, but that's fine, since the first cell is always a_StartingPoint m_Chunk(&a_Chunk), m_BadChunkFound(false) { @@ -72,9 +76,9 @@ cPath::cPath( -cPath::cPath() : m_IsValid(false) +cPath::cPath() : + m_IsValid(false) { - } @@ -170,17 +174,11 @@ bool cPath::StepOnce() // If true, no need to do more checks in that direction - bool DoneEast = false, - DoneWest = false, - DoneNorth = false, - DoneSouth = false; + bool DoneEast = false, DoneWest = false, DoneNorth = false, DoneSouth = false; // If true, we can walk in that direction without changing height // This is used for deciding if to calculate diagonals - bool WalkableEast = false, - WalkableWest = false, - WalkableNorth = false, - WalkableSouth = false; + bool WalkableEast = false, WalkableWest = false, WalkableNorth = false, WalkableSouth = false; // If we can jump without hitting the ceiling if (BodyFitsIn(CurrentCell->m_Location + Vector3i(0, 1, 0), CurrentCell->m_Location)) @@ -211,7 +209,6 @@ bool cPath::StepOnce() { DoneSouth = true; } - } @@ -222,7 +219,7 @@ bool cPath::StepOnce() { for (int y = 0; y >= -3; --y) { - if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(1, y, 0), CurrentCell, NORMAL_G_COST)) + if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(1, y, 0), CurrentCell, NORMAL_G_COST)) { DoneEast = true; if (y == 0) @@ -238,7 +235,7 @@ bool cPath::StepOnce() { for (int y = 0; y >= -3; --y) { - if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(-1, y, 0), CurrentCell, NORMAL_G_COST)) + if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(-1, y, 0), CurrentCell, NORMAL_G_COST)) { DoneWest = true; if (y == 0) @@ -254,7 +251,7 @@ bool cPath::StepOnce() { for (int y = 0; y >= -3; --y) { - if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, y, 1), CurrentCell, NORMAL_G_COST)) + if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, y, 1), CurrentCell, NORMAL_G_COST)) { DoneSouth = true; if (y == 0) @@ -337,10 +334,10 @@ void cPath::BuildPath() { CurrentCell->m_Location.y -= 30; } - m_PathPoints.push_back(CurrentCell->m_Location); // Populate the cPath with points. All midpoints are added. Destination is added. Source is excluded. + m_PathPoints.push_back(CurrentCell->m_Location + ); // Populate the cPath with points. All midpoints are added. Destination is added. Source is excluded. CurrentCell = CurrentCell->m_Parent; } - } @@ -350,7 +347,7 @@ void cPath::BuildPath() void cPath::FinishCalculation() { m_Map.clear(); - m_OpenList = std::priority_queue<cPathCell *, std::vector<cPathCell *>, compareHeuristics>{}; + m_OpenList = std::priority_queue<cPathCell *, std::vector<cPathCell *>, compareHeuristics> {}; } @@ -375,9 +372,9 @@ void cPath::OpenListAdd(cPathCell * a_Cell) { a_Cell->m_Status = eCellStatus::OPENLIST; m_OpenList.push(a_Cell); - #ifdef COMPILING_PATHFIND_DEBUGGER +#ifdef COMPILING_PATHFIND_DEBUGGER si::setBlock(a_Cell->m_Location.x, a_Cell->m_Location.y, a_Cell->m_Location.z, debug_open, SetMini(a_Cell)); - #endif +#endif } @@ -388,15 +385,16 @@ cPathCell * cPath::OpenListPop() // Popping from the open list also means addin { if (m_OpenList.size() == 0) { - return nullptr; // We've exhausted the search space and nothing was found, this will trigger a PATH_NOT_FOUND or NEARBY_FOUND status. + return nullptr; // We've exhausted the search space and nothing was found, this will trigger a PATH_NOT_FOUND + // or NEARBY_FOUND status. } cPathCell * Ret = m_OpenList.top(); m_OpenList.pop(); Ret->m_Status = eCellStatus::CLOSEDLIST; - #ifdef COMPILING_PATHFIND_DEBUGGER +#ifdef COMPILING_PATHFIND_DEBUGGER si::setBlock((Ret)->m_Location.x, (Ret)->m_Location.y, (Ret)->m_Location.z, debug_closed, SetMini(Ret)); - #endif +#endif return Ret; } @@ -440,20 +438,22 @@ void cPath::ProcessCell(cPathCell * a_Cell, cPathCell * a_Caller, int a_GDelta) a_Cell->m_G = 0; } - // Calculate H. This is A*'s Heuristics value. - #if DISTANCE_MANHATTAN == 1 - // Manhattan distance. DeltaX + DeltaY + DeltaZ. - a_Cell->m_H = 10 * (abs(a_Cell->m_Location.x-m_Destination.x) + abs(a_Cell->m_Location.y-m_Destination.y) + abs(a_Cell->m_Location.z-m_Destination.z)); - #else - // Euclidian distance. sqrt(DeltaX^2 + DeltaY^2 + DeltaZ^2), more precise. - a_Cell->m_H = static_cast<decltype(a_Cell->m_H)>((a_Cell->m_Location - m_Destination).Length() * 10); - #endif - - #if HEURISTICS_ONLY == 1 - a_Cell->m_F = a_Cell->m_H; // Greedy search. https://en.wikipedia.org/wiki/Greedy_search - #else - a_Cell->m_F = a_Cell->m_H + a_Cell->m_G; // Regular A*. - #endif +// Calculate H. This is A*'s Heuristics value. +#if DISTANCE_MANHATTAN == 1 + // Manhattan distance. DeltaX + DeltaY + DeltaZ. + a_Cell->m_H = 10 * + (abs(a_Cell->m_Location.x - m_Destination.x) + abs(a_Cell->m_Location.y - m_Destination.y) + + abs(a_Cell->m_Location.z - m_Destination.z)); +#else + // Euclidian distance. sqrt(DeltaX^2 + DeltaY^2 + DeltaZ^2), more precise. + a_Cell->m_H = static_cast<decltype(a_Cell->m_H)>((a_Cell->m_Location - m_Destination).Length() * 10); +#endif + +#if HEURISTICS_ONLY == 1 + a_Cell->m_F = a_Cell->m_H; // Greedy search. https://en.wikipedia.org/wiki/Greedy_search +#else + a_Cell->m_F = a_Cell->m_H + a_Cell->m_G; // Regular A*. +#endif OpenListAdd(a_Cell); return; @@ -467,7 +467,6 @@ void cPath::ProcessCell(cPathCell * a_Cell, cPathCell * a_Caller, int a_GDelta) a_Cell->m_H = a_Cell->m_F + a_Cell->m_G; a_Cell->m_Parent = a_Caller; } - } @@ -494,7 +493,8 @@ void cPath::FillCellAttributes(cPathCell & a_Cell) m_BadChunkFound = true; a_Cell.m_IsSolid = true; a_Cell.m_IsSpecial = false; - a_Cell.m_BlockType = E_BLOCK_AIR; // m_BlockType is never used when m_IsSpecial is false, but it may be used if we implement dijkstra + a_Cell.m_BlockType = E_BLOCK_AIR; // m_BlockType is never used when m_IsSpecial is false, but it may be used if + // we implement dijkstra return; } m_Chunk = Chunk; @@ -512,9 +512,11 @@ void cPath::FillCellAttributes(cPathCell & a_Cell) if (BlockTypeIsSpecial(BlockType)) { a_Cell.m_IsSpecial = true; - a_Cell.m_IsSolid = true; // Specials are solids only from a certain direction. But their m_IsSolid is always true + a_Cell.m_IsSolid = + true; // Specials are solids only from a certain direction. But their m_IsSolid is always true } - else if ((!cBlockInfo::IsSolid(a_Cell.m_BlockType)) && IsBlockFence(GetCell(Location + Vector3i(0, -1, 0))->m_BlockType)) + else if ((!cBlockInfo::IsSolid(a_Cell.m_BlockType)) && + IsBlockFence(GetCell(Location + Vector3i(0, -1, 0))->m_BlockType)) { // Nonsolid blocks with fences below them are consider Special Solids. That is, they sometimes behave as solids. a_Cell.m_IsSpecial = true; @@ -526,7 +528,6 @@ void cPath::FillCellAttributes(cPathCell & a_Cell) a_Cell.m_IsSpecial = false; a_Cell.m_IsSolid = cBlockInfo::IsSolid(BlockType); } - } @@ -541,11 +542,11 @@ cPathCell * cPath::GetCell(const Vector3i & a_Location) m_Map[a_Location].m_Location = a_Location; FillCellAttributes(m_Map[a_Location]); m_Map[a_Location].m_Status = eCellStatus::NOLIST; - #ifdef COMPILING_PATHFIND_DEBUGGER - #ifdef COMPILING_PATHFIND_DEBUGGER_MARK_UNCHECKED - si::setBlock(a_Location.x, a_Location.y, a_Location.z, debug_unchecked, Cell->m_IsSolid ? NORMAL : MINI); - #endif - #endif +#ifdef COMPILING_PATHFIND_DEBUGGER +#ifdef COMPILING_PATHFIND_DEBUGGER_MARK_UNCHECKED + si::setBlock(a_Location.x, a_Location.y, a_Location.z, debug_unchecked, Cell->m_IsSolid ? NORMAL : MINI); +#endif +#endif return &m_Map[a_Location]; } else @@ -581,7 +582,11 @@ bool cPath::BodyFitsIn(const Vector3i & a_Location, const Vector3i & a_Source) { if (CurrentCell->m_IsSpecial) { - if (SpecialIsSolidFromThisDirection(CurrentCell->m_BlockType, CurrentCell->m_BlockMeta, a_Location - a_Source)) + if (SpecialIsSolidFromThisDirection( + CurrentCell->m_BlockType, + CurrentCell->m_BlockMeta, + a_Location - a_Source + )) { return false; } @@ -629,7 +634,7 @@ bool cPath::BlockTypeIsSpecial(BLOCKTYPE a_Type) -bool cPath::SpecialIsSolidFromThisDirection(BLOCKTYPE a_Type, NIBBLETYPE a_Meta, const Vector3i & a_Direction) +bool cPath::SpecialIsSolidFromThisDirection(BLOCKTYPE a_Type, NIBBLETYPE a_Meta, const Vector3i & a_Direction) { if (a_Direction == Vector3i(0, 0, 0)) { diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h index 90b2525f7..78abf7c2a 100644 --- a/src/Mobs/Path.h +++ b/src/Mobs/Path.h @@ -12,42 +12,55 @@ class cPath; #include "../FastRandom.h" #ifdef COMPILING_PATHFIND_DEBUGGER - /* Note: the COMPILING_PATHFIND_DEBUGGER flag is used by Native / WiseOldMan95 to debug - this class outside of Cuberite. This preprocessor flag is never set when compiling Cuberite. */ - #include "PathFinderIrrlicht_Head.h" +/* Note: the COMPILING_PATHFIND_DEBUGGER flag is used by Native / WiseOldMan95 to debug +this class outside of Cuberite. This preprocessor flag is never set when compiling Cuberite. */ +#include "PathFinderIrrlicht_Head.h" #endif -//fwd: ../Chunk.h +// fwd: ../Chunk.h class cChunk; /* Various little structs and classes */ -enum class ePathFinderStatus {CALCULATING, PATH_FOUND, PATH_NOT_FOUND, NEARBY_FOUND}; -enum class eCellStatus {OPENLIST, CLOSEDLIST, NOLIST}; +enum class ePathFinderStatus +{ + CALCULATING, + PATH_FOUND, + PATH_NOT_FOUND, + NEARBY_FOUND +}; +enum class eCellStatus +{ + OPENLIST, + CLOSEDLIST, + NOLIST +}; /** The pathfinder has 3 types of cells (cPathCell). 1 - empty. m_IsSolid is false, m_IsSpecial is false. Air cells are always traversable by A*. 2 - occupied / solid. m_IsSolid is true, m_IsSpecial is false. Air cells are never traversable by A*. 3 - Special. m_IsSolid is true, m_IsSpecial is true. These cells are special: They may either behave as empty -or as occupied / solid, depending on the mob's direction of movement. For instance, an airblock above a fence is a special cell, -because when mobs attempt to travel to it by jumping, it acts as a solid. But when mobs fall and land on top of a fence, -it acts as air. Special cells include: Doors, ladders, trapdoors, water, gates. +or as occupied / solid, depending on the mob's direction of movement. For instance, an airblock above a fence is a +special cell, because when mobs attempt to travel to it by jumping, it acts as a solid. But when mobs fall and land on +top of a fence, it acts as air. Special cells include: Doors, ladders, trapdoors, water, gates. The main function which handles special blocks is SpecialIsSolidFromThisDirection. This function receives a BlockType, a meta, and a direction of travel, then it uses those 3 parameters to decide whether the special block should behave as a solid or as air in this particular direction of travel. -Currently, only fences and water are handled properly. The function always returns "true" (meaning: treat as occuiped/solid) for -the rest of the blocks. This will be fixed once the physics engine issues are fixed. */ +Currently, only fences and water are handled properly. The function always returns "true" (meaning: treat as +occuiped/solid) for the rest of the blocks. This will be fixed once the physics engine issues are fixed. */ struct cPathCell { - Vector3i m_Location; // Location of the cell in the world. + Vector3i m_Location; // Location of the cell in the world. int m_F, m_G, m_H; // F, G, H as defined in regular A*. eCellStatus m_Status; // Which list is the cell in? Either non, open, or closed. cPathCell * m_Parent; // Cell's parent, as defined in regular A*. - bool m_IsSolid; // Is the cell an air or a solid? Partial solids are considered solids. If m_IsSpecial is true, this is always true. - bool m_IsSpecial; // The cell is special - it acts as "solid" or "air" depending on direction, e.g. door or top of fence. + bool m_IsSolid; // Is the cell an air or a solid? Partial solids are considered solids. If m_IsSpecial is true, + // this is always true. + bool m_IsSpecial; // The cell is special - it acts as "solid" or "air" depending on direction, e.g. door or top of + // fence. BLOCKTYPE m_BlockType; NIBBLETYPE m_BlockMeta; }; @@ -57,8 +70,8 @@ struct cPathCell class compareHeuristics { -public: - bool operator()(cPathCell * & a_V1, cPathCell * & a_V2); + public: + bool operator()(cPathCell *& a_V1, cPathCell *& a_V2); }; @@ -67,20 +80,26 @@ public: class cPath { -public: + public: /** Creates a pathfinder instance. After calling this, you are expected to call CalculationStep() once per tick or once per several ticks until it returns something other than CALCULATING. - @param a_StartingPoint The function expects this position to be the lowest block the mob is in, a rule of thumb: "The block where the Zombie's knees are at". + @param a_StartingPoint The function expects this position to be the lowest block the mob is in, a rule of thumb: + "The block where the Zombie's knees are at". @param a_EndingPoint "The block where the Zombie's knees want to be". @param a_MaxSteps The maximum steps before giving up. - @param a_BoundingBoxWidth the character's boundingbox width in blocks. Currently the parameter is ignored and 1 is assumed. - @param a_BoundingBoxHeight the character's boundingbox width in blocks. Currently the parameter is ignored and 2 is assumed. */ + @param a_BoundingBoxWidth the character's boundingbox width in blocks. Currently the parameter is ignored and 1 is + assumed. + @param a_BoundingBoxHeight the character's boundingbox width in blocks. Currently the parameter is ignored and 2 is + assumed. */ cPath( cChunk & a_Chunk, - const Vector3d & a_StartingPoint, const Vector3d & a_EndingPoint, int a_MaxSteps, - double a_BoundingBoxWidth, double a_BoundingBoxHeight + const Vector3d & a_StartingPoint, + const Vector3d & a_EndingPoint, + int a_MaxSteps, + double a_BoundingBoxWidth, + double a_BoundingBoxHeight ); /** Creates an invalid path which is not usable. You shouldn't call any method other than isValid on such a path. */ @@ -94,11 +113,11 @@ public: cPath & operator=(cPath && a_other) = delete; /** Performs part of the path calculation and returns the appropriate status. - If PATH_FOUND is returned, the path was found, and you can call query the instance for waypoints via GetNextWayPoint, etc. - If NEARBY_FOUND is returned, it means that the destination is not reachable, but a nearby destination - is reachable. If the user likes the alternative destination, they can call AcceptNearbyPath to treat the path as found, - and to make consequent calls to step return PATH_FOUND - If PATH_NOT_FOUND is returned, then no path was found. */ + If PATH_FOUND is returned, the path was found, and you can call query the instance for waypoints via + GetNextWayPoint, etc. If NEARBY_FOUND is returned, it means that the destination is not reachable, but a nearby + destination is reachable. If the user likes the alternative destination, they can call AcceptNearbyPath to treat the + path as found, and to make consequent calls to step return PATH_FOUND If PATH_NOT_FOUND is returned, then no path + was found. */ ePathFinderStatus CalculationStep(cChunk & a_Chunk); /** Called after the PathFinder's step returns NEARBY_FOUND. @@ -136,10 +155,7 @@ public: /** Returns true if this path is properly initialized. Returns false if this path was initialized with an empty constructor. If false, the path is unusable and you should not call any methods. */ - inline bool IsValid() const - { - return m_IsValid; - } + inline bool IsValid() const { return m_IsValid; } /** The amount of waypoints left to return. */ inline size_t WayPointsLeft() const @@ -151,12 +167,12 @@ public: -private: - + private: /* General */ bool StepOnce(); // The public version just calls this version * CALCULATIONS_PER_CALL times. void FinishCalculation(); // Clears the memory used for calculating the path. - void FinishCalculation(ePathFinderStatus a_NewStatus); // Clears the memory used for calculating the path and changes the status. + void FinishCalculation(ePathFinderStatus a_NewStatus + ); // Clears the memory used for calculating the path and changes the status. void AttemptToFindAlternative(); void BuildPath(); @@ -166,11 +182,11 @@ private: bool ProcessIfWalkable(const Vector3i & a_Location, cPathCell * a_Source, int a_Cost); /* Map management */ - void ProcessCell(cPathCell * a_Cell, cPathCell * a_Caller, int a_GDelta); + void ProcessCell(cPathCell * a_Cell, cPathCell * a_Caller, int a_GDelta); cPathCell * GetCell(const Vector3i & a_location); /* Pathfinding fields */ - std::priority_queue<cPathCell *, std::vector<cPathCell *>, compareHeuristics> m_OpenList; + std::priority_queue<cPathCell *, std::vector<cPathCell *>, compareHeuristics> m_OpenList; std::unordered_map<Vector3i, cPathCell, VectorHasher<int>> m_Map; Vector3i m_Destination; Vector3i m_Source; @@ -197,9 +213,9 @@ private: bool IsWalkable(const Vector3i & a_Location, const Vector3i & a_Source); bool BodyFitsIn(const Vector3i & a_Location, const Vector3i & a_Source); bool BlockTypeIsSpecial(BLOCKTYPE a_Type); - bool SpecialIsSolidFromThisDirection(BLOCKTYPE a_Type, NIBBLETYPE a_Meta, const Vector3i & a_Direction); + bool SpecialIsSolidFromThisDirection(BLOCKTYPE a_Type, NIBBLETYPE a_Meta, const Vector3i & a_Direction); bool HasSolidBelow(const Vector3i & a_Location); - #ifdef COMPILING_PATHFIND_DEBUGGER - #include "../path_irrlicht.cpp" - #endif +#ifdef COMPILING_PATHFIND_DEBUGGER +#include "../path_irrlicht.cpp" +#endif }; diff --git a/src/Mobs/PathFinder.cpp b/src/Mobs/PathFinder.cpp index 2e832918a..0fb2dda20 100644 --- a/src/Mobs/PathFinder.cpp +++ b/src/Mobs/PathFinder.cpp @@ -9,10 +9,7 @@ cPathFinder::cPathFinder(float a_MobWidth, float a_MobHeight) : - m_Width(a_MobWidth), - m_Height(a_MobHeight), - m_GiveUpCounter(0), - m_NotFoundCooldown(0) + m_Width(a_MobWidth), m_Height(a_MobHeight), m_GiveUpCounter(0), m_NotFoundCooldown(0) { } @@ -20,7 +17,13 @@ cPathFinder::cPathFinder(float a_MobWidth, float a_MobHeight) : -ePathFinderStatus cPathFinder::GetNextWayPoint(cChunk & a_Chunk, const Vector3d & a_Source, Vector3d * a_Destination, Vector3d * a_OutputWaypoint, bool a_DontCare) +ePathFinderStatus cPathFinder::GetNextWayPoint( + cChunk & a_Chunk, + const Vector3d & a_Source, + Vector3d * a_Destination, + Vector3d * a_OutputWaypoint, + bool a_DontCare +) { m_FinalDestination = *a_Destination; m_Source = a_Source; @@ -69,11 +72,13 @@ ePathFinderStatus cPathFinder::GetNextWayPoint(cChunk & a_Chunk, const Vector3d if (a_DontCare) { m_FinalDestination = m_PathDestination; - *a_Destination = m_FinalDestination; // Modify the mob's final destination because it doesn't care about reaching an exact spot + *a_Destination = m_FinalDestination; // Modify the mob's final destination because it doesn't care + // about reaching an exact spot } else { - m_DeviationOrigin = m_FinalDestination; // This is the only case in which m_DeviationOrigin != m_PathDestination + m_DeviationOrigin = + m_FinalDestination; // This is the only case in which m_DeviationOrigin != m_PathDestination } return ePathFinderStatus::CALCULATING; // The next call will trigger the PATH_FOUND case @@ -124,7 +129,6 @@ ePathFinderStatus cPathFinder::GetNextWayPoint(cChunk & a_Chunk, const Vector3d { *a_OutputWaypoint = m_FinalDestination; return ePathFinderStatus::PATH_FOUND; - } else { @@ -139,7 +143,8 @@ ePathFinderStatus cPathFinder::GetNextWayPoint(cChunk & a_Chunk, const Vector3d Waypoint.y = 0; Source.y = 0; - if (m_Path->IsFirstPoint() || (((Waypoint - Source).SqrLength() < WAYPOINT_RADIUS) && (m_Source.y >= m_WayPoint.y))) + if (m_Path->IsFirstPoint() || + (((Waypoint - Source).SqrLength() < WAYPOINT_RADIUS) && (m_Source.y >= m_WayPoint.y))) { // if the mob has just started or if the mob reached a waypoint, give them a new waypoint. m_WayPoint = m_Path->GetNextPoint(); @@ -148,7 +153,8 @@ ePathFinderStatus cPathFinder::GetNextWayPoint(cChunk & a_Chunk, const Vector3d } else { - // Otherwise, the mob is still walking towards its waypoint, we'll patiently wait. We won't update m_WayPoint. + // Otherwise, the mob is still walking towards its waypoint, we'll patiently wait. We won't update + // m_WayPoint. *a_OutputWaypoint = m_WayPoint; return ePathFinderStatus::PATH_FOUND; } @@ -161,7 +167,7 @@ ePathFinderStatus cPathFinder::GetNextWayPoint(cChunk & a_Chunk, const Vector3d -void cPathFinder::ResetPathFinding(cChunk &a_Chunk) +void cPathFinder::ResetPathFinding(cChunk & a_Chunk) { m_GiveUpCounter = 40; m_NoPathToTarget = false; @@ -192,26 +198,22 @@ bool cPathFinder::EnsureProperPoint(Vector3d & a_Vector, cChunk & a_Chunk) if (!cChunkDef::IsValidHeight(Below)) { return false; - } auto BelowRel = cChunkDef::AbsoluteToRelative(Below); Chunk->GetBlockTypeMeta(BelowRel, BlockType, BlockMeta); if (!(IsWaterOrSolid(BlockType))) { - constexpr std::array<Vector3i, 8> Offsets = - { - { - {-1, 0, 0}, - {1, 0, 0}, - {0, 0, -1}, - {0, 0, 1}, - {-1, 0, -1}, - {-1, 0, 1}, - {1, 0, -1}, - {1, 0, 1}, - } - }; + constexpr std::array<Vector3i, 8> Offsets = {{ + {-1, 0, 0}, + {1, 0, 0}, + {0, 0, -1}, + {0, 0, 1}, + {-1, 0, -1}, + {-1, 0, 1}, + {1, 0, -1}, + {1, 0, 1}, + }}; // Looks for a neighbouring block one block in x or z direction that is water or solid. bool InTheAir = true; diff --git a/src/Mobs/PathFinder.h b/src/Mobs/PathFinder.h index a4843744a..0c7c8aa5f 100644 --- a/src/Mobs/PathFinder.h +++ b/src/Mobs/PathFinder.h @@ -7,11 +7,12 @@ /** This class wraps cPath. cPath is a "dumb device" - You give it point A and point B, and it returns a full path path. cPathFinder - You give it a constant stream of point A (where you are) and point B (where you want to go), -and it tells you where to go next. It manages path recalculation internally, and is much more efficient that calling cPath every step. */ +and it tells you where to go next. It manages path recalculation internally, and is much more efficient that calling +cPath every step. */ class cPathFinder { -public: + public: /** Creates a cPathFinder instance. Each mob should have one cPathFinder throughout its lifetime. @param a_MobWidth The mob width. @param a_MobHeight The mob height. @@ -23,23 +24,32 @@ public: The mob is expected to call this function tick as long as it is following a path. @param a_Chunk The chunk in which the mob is currently at. @param a_Source The mob's position. a_Source's coordinates are expected to be within the chunk given in a_Chunk. - @param a_Destination The position the mob would like to reach. If a_ExactPath is true, the PathFinder may modify this. + @param a_Destination The position the mob would like to reach. If a_ExactPath is true, the PathFinder may modify + this. @param a_OutputWaypoint An output parameter: The next waypoint to go to. @param a_DontCare If true, the mob doesn't care where to go, and the Pathfinder may modify a_Destination. This should usually be false. An exception is a wandering idle mob which doesn't care about its final destination. In the future, idle mobs shouldn't use A* at all. Returns an ePathFinderStatus. - ePathFinderStatus:CALCULATING - The PathFinder is still processing a path. Nothing was written to a_OutputWaypoint. The mob should probably not move. - ePathFinderStatus:PATH_FOUND - The PathFinder has found a path to the target. The next waypoint was written a_OutputWaypoint. The mob should probably move to a_OutputWaypoint. - ePathFinderStatus:NEARBY_FOUND - The PathFinder did not find a destination to the target but did find a nearby spot. The next waypoint was written a_OutputWaypoint. The mob should probably move to a_OutputWaypoint. - ePathFinderStatus:PATH_NOT_FOUND - The PathFinder did not find a destination to the target. Nothing was written to a_OutputWaypoint. The mob should probably not move. + ePathFinderStatus:CALCULATING - The PathFinder is still processing a path. Nothing was written to a_OutputWaypoint. + The mob should probably not move. ePathFinderStatus:PATH_FOUND - The PathFinder has found a path to the target. The + next waypoint was written a_OutputWaypoint. The mob should probably move to a_OutputWaypoint. + ePathFinderStatus:NEARBY_FOUND - The PathFinder did not find a destination to the target but did find a nearby spot. + The next waypoint was written a_OutputWaypoint. The mob should probably move to a_OutputWaypoint. + ePathFinderStatus:PATH_NOT_FOUND - The PathFinder did not find a destination to the target. Nothing was written to + a_OutputWaypoint. The mob should probably not move. Note: Once NEARBY_FOUND is returned once, subsequent calls return PATH_FOUND. */ - ePathFinderStatus GetNextWayPoint(cChunk & a_Chunk, const Vector3d & a_Source, Vector3d * a_Destination, Vector3d * a_OutputWaypoint, bool a_DontCare = false); - -private: - + ePathFinderStatus GetNextWayPoint( + cChunk & a_Chunk, + const Vector3d & a_Source, + Vector3d * a_Destination, + Vector3d * a_OutputWaypoint, + bool a_DontCare = false + ); + + private: /** The width of the Mob which owns this PathFinder. */ float m_Width; @@ -78,11 +88,12 @@ private: /** Ensures the location is not in the air or under water. May change the Y coordinate of the given vector. 1. If a_Vector is the position of water, a_Vector's Y will be modified to point to the first air block above it. - 2. If a_Vector is the position of air, a_Vector's Y will be modified to point to the first airblock below it which has solid or water beneath. */ + 2. If a_Vector is the position of air, a_Vector's Y will be modified to point to the first airblock below it which + has solid or water beneath. */ bool EnsureProperPoint(Vector3d & a_Vector, cChunk & a_Chunk); /** Resets a pathfinding task, typically because m_FinalDestination has deviated too much from m_DeviationOrigin. */ - void ResetPathFinding(cChunk &a_Chunk); + void ResetPathFinding(cChunk & a_Chunk); /** Return true the the blocktype is either water or solid */ bool IsWaterOrSolid(BLOCKTYPE a_BlockType); diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index 5e7c18bf8..d279634a7 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -10,8 +10,7 @@ cPig::cPig(void) : - Super("Pig", mtPig, "entity.pig.hurt", "entity.pig.death", "entity.pig.ambient", 0.9f, 0.9f), - m_bIsSaddled(false) + Super("Pig", mtPig, "entity.pig.hurt", "entity.pig.death", "entity.pig.ambient", 0.9f, 0.9f), m_bIsSaddled(false) { } @@ -101,7 +100,7 @@ void cPig::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_Attachee->IsPlayer() && (m_Attachee->GetEquippedWeapon().m_ItemType == E_ITEM_CARROT_ON_STICK)) { - MoveToPosition((m_Attachee->GetPosition()) + (m_Attachee->GetLookVector()*10)); + MoveToPosition((m_Attachee->GetPosition()) + (m_Attachee->GetLookVector() * 10)); } } } @@ -125,7 +124,3 @@ bool cPig::DoTakeDamage(TakeDamageInfo & a_TDI) } return true; } - - - - diff --git a/src/Mobs/Pig.h b/src/Mobs/Pig.h index fe2837bec..8fc7bacf0 100644 --- a/src/Mobs/Pig.h +++ b/src/Mobs/Pig.h @@ -7,13 +7,11 @@ -class cPig: - public cPassiveMonster +class cPig : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: cPig(); CLASS_PROTODEF(cPig) @@ -25,19 +23,10 @@ public: virtual void OnRightClicked(cPlayer & a_Player) override; virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void GetFollowedItems(cItems & a_Items) override - { - a_Items.Add(E_ITEM_CARROT); - } + virtual void GetFollowedItems(cItems & a_Items) override { a_Items.Add(E_ITEM_CARROT); } bool IsSaddled(void) const { return m_bIsSaddled; } -private: - + private: bool m_bIsSaddled; - -} ; - - - - +}; diff --git a/src/Mobs/Rabbit.cpp b/src/Mobs/Rabbit.cpp index d0d2fe4c1..01854af19 100644 --- a/src/Mobs/Rabbit.cpp +++ b/src/Mobs/Rabbit.cpp @@ -10,9 +10,12 @@ cRabbit::cRabbit(void) : - cRabbit(static_cast<eRabbitType>(GetRandomProvider().RandInt<UInt8>( - static_cast<UInt8>(eRabbitType::SaltAndPepper) // Max possible Rabbit-Type - )), 0) + cRabbit( + static_cast<eRabbitType>(GetRandomProvider().RandInt<UInt8>( + static_cast<UInt8>(eRabbitType::SaltAndPepper) // Max possible Rabbit-Type + )), + 0 + ) { } @@ -49,4 +52,3 @@ void cRabbit::GetDrops(cItems & a_Drops, cEntity * a_Killer) RareDrops.Add(cItem(E_ITEM_RABBITS_FOOT)); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); } - diff --git a/src/Mobs/Rabbit.h b/src/Mobs/Rabbit.h index 33a9f7fa4..4a1fe9784 100644 --- a/src/Mobs/Rabbit.h +++ b/src/Mobs/Rabbit.h @@ -9,12 +9,12 @@ enum class eRabbitType : UInt8 { - Brown = 0, - White = 1, - Black = 2, - BlackAndWhite = 3, - Gold = 4, - SaltAndPepper = 5, + Brown = 0, + White = 1, + Black = 2, + BlackAndWhite = 3, + Gold = 4, + SaltAndPepper = 5, TheKillerBunny = 99 }; @@ -22,13 +22,11 @@ enum class eRabbitType : UInt8 -class cRabbit: - public cPassiveMonster +class cRabbit : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: cRabbit(); cRabbit(eRabbitType Type, int MoreCarrotTicks = 0); @@ -42,11 +40,10 @@ public: a_Items.Add(E_BLOCK_DANDELION); } - eRabbitType GetRabbitType() const { return m_Type; } - int GetMoreCarrotTicks() const { return m_MoreCarrotTicks; } - -private: + eRabbitType GetRabbitType() const { return m_Type; } + int GetMoreCarrotTicks() const { return m_MoreCarrotTicks; } + private: eRabbitType m_Type; int m_MoreCarrotTicks; // Ticks until the Rabbit eat planted Carrots -} ; +}; diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index be4def2b7..cc0c0d880 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -113,11 +113,13 @@ void cSheep::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) if (m_TimeToStopEating == 0) { - if (m_World->GetBlock({ PosX, PosY, PosZ }) == E_BLOCK_GRASS) // Make sure grass hasn't been destroyed in the meantime + if (m_World->GetBlock({PosX, PosY, PosZ}) == + E_BLOCK_GRASS) // Make sure grass hasn't been destroyed in the meantime { // The sheep ate the grass so we change it to dirt - m_World->SetBlock({ PosX, PosY, PosZ }, E_BLOCK_DIRT, 0); - GetWorld()->BroadcastSoundParticleEffect(EffectID::PARTICLE_BLOCK_BREAK, { PosX, PosY, PosZ }, E_BLOCK_GRASS); + m_World->SetBlock({PosX, PosY, PosZ}, E_BLOCK_DIRT, 0); + GetWorld() + ->BroadcastSoundParticleEffect(EffectID::PARTICLE_BLOCK_BREAK, {PosX, PosY, PosZ}, E_BLOCK_GRASS); m_IsSheared = false; m_World->BroadcastEntityMetadata(*this); } @@ -127,7 +129,7 @@ void cSheep::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (GetRandomProvider().RandBool(1.0 / 600.0)) { - if (m_World->GetBlock({ PosX, PosY, PosZ }) == E_BLOCK_GRASS) + if (m_World->GetBlock({PosX, PosY, PosZ}) == E_BLOCK_GRASS) { m_World->BroadcastEntityAnimation(*this, EntityAnimation::SheepEatsGrass); m_TimeToStopEating = 40; @@ -145,26 +147,25 @@ void cSheep::InheritFromParents(cMonster * a_Parent1, cMonster * a_Parent2) static const struct { short Parent1, Parent2, Child; - } ColorInheritance[] = - { - { E_META_WOOL_BLUE, E_META_WOOL_RED, E_META_WOOL_PURPLE }, - { E_META_WOOL_BLUE, E_META_WOOL_GREEN, E_META_WOOL_CYAN }, - { E_META_WOOL_YELLOW, E_META_WOOL_RED, E_META_WOOL_ORANGE }, - { E_META_WOOL_GREEN, E_META_WOOL_WHITE, E_META_WOOL_LIGHTGREEN }, - { E_META_WOOL_RED, E_META_WOOL_WHITE, E_META_WOOL_PINK }, - { E_META_WOOL_WHITE, E_META_WOOL_BLACK, E_META_WOOL_GRAY }, - { E_META_WOOL_PURPLE, E_META_WOOL_PINK, E_META_WOOL_MAGENTA }, - { E_META_WOOL_WHITE, E_META_WOOL_GRAY, E_META_WOOL_LIGHTGRAY }, - { E_META_WOOL_BLUE, E_META_WOOL_WHITE, E_META_WOOL_LIGHTBLUE }, + } ColorInheritance[] = { + {E_META_WOOL_BLUE, E_META_WOOL_RED, E_META_WOOL_PURPLE}, + {E_META_WOOL_BLUE, E_META_WOOL_GREEN, E_META_WOOL_CYAN}, + {E_META_WOOL_YELLOW, E_META_WOOL_RED, E_META_WOOL_ORANGE}, + {E_META_WOOL_GREEN, E_META_WOOL_WHITE, E_META_WOOL_LIGHTGREEN}, + {E_META_WOOL_RED, E_META_WOOL_WHITE, E_META_WOOL_PINK}, + {E_META_WOOL_WHITE, E_META_WOOL_BLACK, E_META_WOOL_GRAY}, + {E_META_WOOL_PURPLE, E_META_WOOL_PINK, E_META_WOOL_MAGENTA}, + {E_META_WOOL_WHITE, E_META_WOOL_GRAY, E_META_WOOL_LIGHTGRAY}, + {E_META_WOOL_BLUE, E_META_WOOL_WHITE, E_META_WOOL_LIGHTBLUE}, }; cSheep * Parent1 = static_cast<cSheep *>(a_Parent1); cSheep * Parent2 = static_cast<cSheep *>(a_Parent2); for (size_t i = 0; i < ARRAYCOUNT(ColorInheritance); i++) { - if ( - ((Parent1->GetFurColor() == ColorInheritance[i].Parent1) && (Parent2->GetFurColor() == ColorInheritance[i].Parent2)) || - ((Parent1->GetFurColor() == ColorInheritance[i].Parent2) && (Parent2->GetFurColor() == ColorInheritance[i].Parent1)) - ) + if (((Parent1->GetFurColor() == ColorInheritance[i].Parent1) && + (Parent2->GetFurColor() == ColorInheritance[i].Parent2)) || + ((Parent1->GetFurColor() == ColorInheritance[i].Parent2) && + (Parent2->GetFurColor() == ColorInheritance[i].Parent1))) { SetFurColor(ColorInheritance[i].Child); return; diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h index 786dad206..b767fc058 100644 --- a/src/Mobs/Sheep.h +++ b/src/Mobs/Sheep.h @@ -7,13 +7,11 @@ -class cSheep: - public cPassiveMonster +class cSheep : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: /** The number is the color of the sheep. Use E_META_WOOL_* constants for the wool color. If you type -1, the server will generate a random color @@ -27,10 +25,7 @@ public: virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void InheritFromParents(cMonster * a_Parent1, cMonster * a_Parent2) override; - virtual void GetFollowedItems(cItems & a_Items) override - { - a_Items.Add(E_ITEM_WHEAT); - } + virtual void GetFollowedItems(cItems & a_Items) override { a_Items.Add(E_ITEM_WHEAT); } /** Generates a random color for the sheep like the vanilla server. The percent's where used are from the wiki: https://minecraft.wiki/w/Sheep#Breeding */ @@ -42,13 +37,8 @@ public: int GetFurColor(void) const { return m_WoolColor; } void SetFurColor(int a_WoolColor) { m_WoolColor = a_WoolColor; } -private: + private: bool m_IsSheared; int m_WoolColor; int m_TimeToStopEating; - -} ; - - - - +}; diff --git a/src/Mobs/Silverfish.cpp b/src/Mobs/Silverfish.cpp index 37684f8bc..76407151e 100644 --- a/src/Mobs/Silverfish.cpp +++ b/src/Mobs/Silverfish.cpp @@ -13,7 +13,15 @@ cSilverfish::cSilverfish() : - Super("Silverfish", mtSilverfish, "entity.silverfish.hurt", "entity.silverfish.death", "entity.silverfish.ambient", 0.4f, 0.3f) + Super( + "Silverfish", + mtSilverfish, + "entity.silverfish.hurt", + "entity.silverfish.death", + "entity.silverfish.ambient", + 0.4f, + 0.3f + ) { } @@ -21,7 +29,7 @@ cSilverfish::cSilverfish() : -bool cSilverfish::DoTakeDamage(TakeDamageInfo &a_TDI) +bool cSilverfish::DoTakeDamage(TakeDamageInfo & a_TDI) { // Call on our brethren to attack! // TODO: stop this if /gamerule mobGriefing is set to false @@ -76,7 +84,7 @@ bool cSilverfish::DoTakeDamage(TakeDamageInfo &a_TDI) { for (int OffsetZ = -HalfSide; OffsetZ <= HalfSide; OffsetZ++) { - if (CheckInfested({ OffsetX, +HalfSide, OffsetZ }) || CheckInfested({ OffsetX, -HalfSide, OffsetZ })) + if (CheckInfested({OffsetX, +HalfSide, OffsetZ}) || CheckInfested({OffsetX, -HalfSide, OffsetZ})) { return true; } @@ -87,7 +95,7 @@ bool cSilverfish::DoTakeDamage(TakeDamageInfo &a_TDI) { for (int OffsetY = -HalfSide + 1; OffsetY <= HalfSide - 1; OffsetY++) { - if (CheckInfested({ OffsetX, OffsetY, +HalfSide }) || CheckInfested({ OffsetX, OffsetY, -HalfSide })) + if (CheckInfested({OffsetX, OffsetY, +HalfSide}) || CheckInfested({OffsetX, OffsetY, -HalfSide})) { return true; } @@ -98,7 +106,7 @@ bool cSilverfish::DoTakeDamage(TakeDamageInfo &a_TDI) { for (int OffsetY = -HalfSide + 1; OffsetY <= HalfSide - 1; OffsetY++) { - if (CheckInfested({ +HalfSide, OffsetY, OffsetZ }) || CheckInfested({ -HalfSide, OffsetY, OffsetZ })) + if (CheckInfested({+HalfSide, OffsetY, OffsetZ}) || CheckInfested({-HalfSide, OffsetY, OffsetZ})) { return true; } diff --git a/src/Mobs/Silverfish.h b/src/Mobs/Silverfish.h index 3b8ffa6e6..1f3c8dcca 100644 --- a/src/Mobs/Silverfish.h +++ b/src/Mobs/Silverfish.h @@ -7,16 +7,14 @@ -class cSilverfish: - public cAggressiveMonster +class cSilverfish : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cSilverfish(); CLASS_PROTODEF(cSilverfish) virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; -} ; +}; diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 12081207f..89f87067c 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -10,7 +10,15 @@ cSkeleton::cSkeleton(void) : - Super("Skeleton", mtSkeleton, "entity.skeleton.hurt", "entity.skeleton.death", "entity.skeleton.ambient", 0.6f, 1.99f), + Super( + "Skeleton", + mtSkeleton, + "entity.skeleton.hurt", + "entity.skeleton.death", + "entity.skeleton.ambient", + 0.6f, + 1.99f + ), m_ChargingBow(false) { } @@ -61,7 +69,8 @@ void cSkeleton::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) bool cSkeleton::Attack(std::chrono::milliseconds a_Dt) { - StopMovingToPosition(); // Todo handle this in a better way, the skeleton does some uneeded recalcs due to inStateChasing + StopMovingToPosition( + ); // Todo handle this in a better way, the skeleton does some uneeded recalcs due to inStateChasing auto & Random = GetRandomProvider(); if (!m_ChargingBow) @@ -73,7 +82,11 @@ bool cSkeleton::Attack(std::chrono::milliseconds a_Dt) if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0)) { - Vector3d Inaccuracy = Vector3d(Random.RandReal<double>(-0.25, 0.25), Random.RandReal<double>(-0.25, 0.25), Random.RandReal<double>(-0.25, 0.25)); + Vector3d Inaccuracy = Vector3d( + Random.RandReal<double>(-0.25, 0.25), + Random.RandReal<double>(-0.25, 0.25), + Random.RandReal<double>(-0.25, 0.25) + ); Vector3d Speed = (GetTarget()->GetPosition() + Inaccuracy - GetPosition()) * 5; Speed.y += Random.RandInt(-1, 1); diff --git a/src/Mobs/Skeleton.h b/src/Mobs/Skeleton.h index 486bfe609..12ca5c1ba 100644 --- a/src/Mobs/Skeleton.h +++ b/src/Mobs/Skeleton.h @@ -7,13 +7,11 @@ -class cSkeleton: - public cAggressiveMonster +class cSkeleton : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cSkeleton(); CLASS_PROTODEF(cSkeleton) @@ -28,8 +26,6 @@ public: bool IsChargingBow() const { return m_ChargingBow; } -private: - + private: bool m_ChargingBow; - -} ; +}; diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 320fa3c8a..43761a6ee 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -10,9 +10,10 @@ cSlime::cSlime(int a_Size) : - Super("Slime", + Super( + "Slime", mtSlime, - fmt::format(FMT_STRING("entity.{}slime.hurt"), GetSizeName(a_Size)), + fmt::format(FMT_STRING("entity.{}slime.hurt"), GetSizeName(a_Size)), fmt::format(FMT_STRING("entity.{}slime.death"), GetSizeName(a_Size)), "", 0.51f * a_Size, @@ -80,17 +81,18 @@ void cSlime::KilledBy(TakeDamageInfo & a_TDI) double AddZ = (i / 2 - 0.5) * m_Size / 4.0; // Queue slimes to be spawned after the 1 second death animation has finished playing: - m_World->ScheduleTask(cTickTime(20), [ - Position = GetPosition() + Vector3d(AddX, 0.5, AddZ), - Yaw = Random.RandReal(360.0f), - Size = m_Size / 2 - ](cWorld & a_World) - { - auto NewSlime = std::make_unique<cSlime>(Size); - NewSlime->SetPosition(Position); - NewSlime->SetYaw(Yaw); - a_World.SpawnMobFinalize(std::move(NewSlime)); - }); + m_World->ScheduleTask( + cTickTime(20), + [Position = GetPosition() + Vector3d(AddX, 0.5, AddZ), + Yaw = Random.RandReal(360.0f), + Size = m_Size / 2](cWorld & a_World) + { + auto NewSlime = std::make_unique<cSlime>(Size); + NewSlime->SetPosition(Position); + NewSlime->SetYaw(Yaw); + a_World.SpawnMobFinalize(std::move(NewSlime)); + } + ); } } Super::KilledBy(a_TDI); @@ -108,7 +110,3 @@ AString cSlime::GetSizeName(int a_Size) } return ""; } - - - - diff --git a/src/Mobs/Slime.h b/src/Mobs/Slime.h index e1be964eb..1bbaa28f2 100644 --- a/src/Mobs/Slime.h +++ b/src/Mobs/Slime.h @@ -7,13 +7,11 @@ -class cSlime: - public cAggressiveMonster +class cSlime : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: /** Creates a slime of the specified size; size can be 1, 2 or 4, with 1 is the smallest and 4 is the tallest. */ cSlime(int a_Size); @@ -30,13 +28,8 @@ public: Returns either "big" or "small". */ static AString GetSizeName(int a_Size); -protected: - + protected: /** Size of the slime, with 1 being the smallest. Vanilla uses sizes 1, 2 and 4 only. */ int m_Size; -} ; - - - - +}; diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index fabcfb070..d5fb015b0 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -67,12 +67,17 @@ bool cSnowGolem::Attack(std::chrono::milliseconds a_Dt) UNUSED(a_Dt); // Comment inherited from skeletons - StopMovingToPosition(); // Todo handle this in a better way, the snowman does some uneeded recalcs due to inStateChasing + StopMovingToPosition( + ); // Todo handle this in a better way, the snowman does some uneeded recalcs due to inStateChasing if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0)) { auto & Random = GetRandomProvider(); - Vector3d Inaccuracy = Vector3d(Random.RandReal<double>(-0.75, 0.75), Random.RandReal<double>(-0.75, 0.75), Random.RandReal<double>(-0.75, 0.75)); + Vector3d Inaccuracy = Vector3d( + Random.RandReal<double>(-0.75, 0.75), + Random.RandReal<double>(-0.75, 0.75), + Random.RandReal<double>(-0.75, 0.75) + ); // The projectile is launched from the head const auto HeadPos = GetPosition().addedY(1.5); diff --git a/src/Mobs/SnowGolem.h b/src/Mobs/SnowGolem.h index 6c6e88868..1d18f6cfe 100644 --- a/src/Mobs/SnowGolem.h +++ b/src/Mobs/SnowGolem.h @@ -7,13 +7,11 @@ -class cSnowGolem: - public cPassiveAggressiveMonster +class cSnowGolem : public cPassiveAggressiveMonster { using Super = cPassiveAggressiveMonster; -public: - + public: cSnowGolem(); CLASS_PROTODEF(cSnowGolem) @@ -21,8 +19,4 @@ public: virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool Attack(std::chrono::milliseconds a_Dt) override; -} ; - - - - +}; diff --git a/src/Mobs/Spider.h b/src/Mobs/Spider.h index 2a0b9861e..92e640b38 100644 --- a/src/Mobs/Spider.h +++ b/src/Mobs/Spider.h @@ -7,13 +7,11 @@ -class cSpider: - public cAggressiveMonster +class cSpider : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cSpider(); CLASS_PROTODEF(cSpider) @@ -21,8 +19,4 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual void EventSeePlayer(cPlayer *, cChunk & a_Chunk) override; virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; -} ; - - - - +}; diff --git a/src/Mobs/Squid.h b/src/Mobs/Squid.h index a2cc48b13..c85c43cea 100644 --- a/src/Mobs/Squid.h +++ b/src/Mobs/Squid.h @@ -7,13 +7,11 @@ -class cSquid: - public cPassiveMonster +class cSquid : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: cSquid(); virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; @@ -24,8 +22,4 @@ public: // Squids do not drown (or float) virtual void HandleAir(void) override {} -} ; - - - - +}; diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index aa5409e4d..b9746f189 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -12,7 +12,15 @@ cVillager::cVillager(eVillagerType VillagerType) : - Super("Villager", mtVillager, "entity.villager.hurt", "entity.villager.death", "entity.villager.ambient", 0.6f, 1.95f), + Super( + "Villager", + mtVillager, + "entity.villager.hurt", + "entity.villager.death", + "entity.villager.ambient", + 0.6f, + 1.95f + ), m_ActionCountDown(-1), m_Type(VillagerType), m_FarmerAction(faIdling), @@ -118,7 +126,9 @@ void cVillager::TickFarmer() MoveToPosition(static_cast<Vector3d>(m_CropsPos) + Vector3d(0.5, 0, 0.5)); // Forcing the farmer to look at the work spots. - Vector3d Direction = (m_FinalDestination - (GetPosition() + Vector3d(0, 1.6, 0))); // We get the direction from the eyes of the farmer to the work spot. + Vector3d Direction = + (m_FinalDestination - (GetPosition() + Vector3d(0, 1.6, 0)) + ); // We get the direction from the eyes of the farmer to the work spot. Direction.Normalize(); SetPitch(std::asin(-Direction.y) / M_PI * 180); } @@ -155,7 +165,6 @@ void cVillager::TickFarmer() { ScanAreaForWork(); } - } @@ -171,17 +180,18 @@ void cVillager::ScanAreaForWork() // Read area to be checked for crops. cBlockArea Surrounding; - Surrounding.Read( - *m_World, - MinPos, MaxPos - ); + Surrounding.Read(*m_World, MinPos, MaxPos); for (int I = 0; I < FARMER_RANDOM_TICK_SPEED; I++) { for (int Y = MinPos.y; Y <= MaxPos.y; Y++) { // Pick random coordinates and check for crops. - Vector3i CandidatePos(MinPos.x + m_World->GetTickRandomNumber(MaxPos.x - MinPos.x - 1), Y, MinPos.z + m_World->GetTickRandomNumber(MaxPos.z - MinPos.z - 1)); + Vector3i CandidatePos( + MinPos.x + m_World->GetTickRandomNumber(MaxPos.x - MinPos.x - 1), + Y, + MinPos.z + m_World->GetTickRandomNumber(MaxPos.z - MinPos.z - 1) + ); // A villager can harvest this. if (IsHarvestable(CandidatePos)) @@ -222,7 +232,11 @@ void cVillager::HandleFarmerTryHarvestCrops() // Check if the blocks didn't change while the villager was walking to the coordinates. if (IsHarvestable(m_CropsPos)) { - m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_BLOCK_BREAK, m_CropsPos, m_World->GetBlock(m_CropsPos)); + m_World->BroadcastSoundParticleEffect( + EffectID::PARTICLE_BLOCK_BREAK, + m_CropsPos, + m_World->GetBlock(m_CropsPos) + ); m_World->DropBlockAsPickups(m_CropsPos, this, nullptr); // Applying 0.5 second cooldown. m_ActionCountDown = 10; @@ -239,7 +253,7 @@ void cVillager::CheckForNearbyCrops() // Search for adjacent crops - constexpr std::array<Vector3i, 4> Directions = { Vector3i{0, 0, -1}, {0, 0, 1}, {1, 0, 0}, {-1, 0, 0} }; + constexpr std::array<Vector3i, 4> Directions = {Vector3i {0, 0, -1}, {0, 0, 1}, {1, 0, 0}, {-1, 0, 0}}; for (Vector3i Direction : Directions) { @@ -257,7 +271,6 @@ void cVillager::CheckForNearbyCrops() MoveToPosition(static_cast<Vector3d>(m_CropsPos) + Vector3d(0.5, 0, 0.5)); return; } - } // There is no more work to do around the previous crops. @@ -350,10 +363,8 @@ void cVillager::HandleFarmerTryPlaceCrops() bool cVillager::CanPlantCrops() { - return m_Inventory.HasItems(cItem(E_ITEM_SEEDS)) || - m_Inventory.HasItems(cItem(E_ITEM_BEETROOT_SEEDS)) || - m_Inventory.HasItems(cItem(E_ITEM_POTATO)) || - m_Inventory.HasItems(cItem(E_ITEM_CARROT)); + return m_Inventory.HasItems(cItem(E_ITEM_SEEDS)) || m_Inventory.HasItems(cItem(E_ITEM_BEETROOT_SEEDS)) || + m_Inventory.HasItems(cItem(E_ITEM_POTATO)) || m_Inventory.HasItems(cItem(E_ITEM_CARROT)); } @@ -395,7 +406,8 @@ bool cVillager::IsHarvestable(Vector3i a_CropsPos) bool cVillager::IsPlantable(Vector3i a_CropsPos) { - return (m_World->GetBlock(a_CropsPos.addedY(-1)) == E_BLOCK_FARMLAND) && (m_World->GetBlock(a_CropsPos) == E_BLOCK_AIR); + return (m_World->GetBlock(a_CropsPos.addedY(-1)) == E_BLOCK_FARMLAND) && + (m_World->GetBlock(a_CropsPos) == E_BLOCK_AIR); } diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h index ef1c9e70f..947c1981a 100644 --- a/src/Mobs/Villager.h +++ b/src/Mobs/Villager.h @@ -8,23 +8,21 @@ -class cVillager: - public cPassiveMonster +class cVillager : public cPassiveMonster { using Super = cPassiveMonster; -public: - + public: enum eVillagerType { - vtFarmer = 0, - vtLibrarian = 1, - vtPriest = 2, + vtFarmer = 0, + vtLibrarian = 1, + vtPriest = 2, vtBlacksmith = 3, - vtButcher = 4, - vtGeneric = 5, + vtButcher = 4, + vtGeneric = 5, vtMax - } ; + }; cVillager(eVillagerType VillagerType); @@ -35,8 +33,8 @@ public: // cEntity overrides virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; - virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void KilledBy (TakeDamageInfo & a_TDI) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + virtual void KilledBy(TakeDamageInfo & a_TDI) override; // cVillager functions /** Returns the villager hidden inventory (8 slots). */ @@ -58,7 +56,7 @@ public: faIdling, faPlanting, faHarvesting, - } ; + }; static const int FARMER_RANDOM_TICK_SPEED = 5; /** With 10% chance, it takes about 20 seconds to find a spot. */ @@ -69,13 +67,16 @@ public: /** Tick function for farmers. */ void TickFarmer(); - /** Searches in a 31x3x31 area to harvest crops or spaces to plant crops. If it found some it will navigate to them. */ + /** Searches in a 31x3x31 area to harvest crops or spaces to plant crops. If it found some it will navigate to them. + */ void ScanAreaForWork(); - /** Looks if the farmer has reached it's destination, and if it's still crops and the destination is closer then 1 block it will harvest them. */ + /** Looks if the farmer has reached it's destination, and if it's still crops and the destination is closer then 1 + * block it will harvest them. */ void HandleFarmerTryHarvestCrops(); - /** Looks if the farmer has reached it's destination, and if it's still non obstructed farmland and the destination is closer then 1 block it will plant crops. */ + /** Looks if the farmer has reached it's destination, and if it's still non obstructed farmland and the destination + * is closer then 1 block it will plant crops. */ void HandleFarmerTryPlaceCrops(); /** Checking for harvesting or planting nearby crops */ @@ -85,25 +86,16 @@ public: bool CanPlantCrops(); /** Returns whether the farmer is not working. */ - bool IsIdling() - { - return m_FarmerAction == faIdling; - } + bool IsIdling() { return m_FarmerAction == faIdling; } // Get and set functions. - int GetVilType(void) const { return m_Type; } + int GetVilType(void) const { return m_Type; } eFarmerAction GetFarmerAction(void) const { return m_FarmerAction; } -private: - + private: int m_ActionCountDown; int m_Type; eFarmerAction m_FarmerAction; Vector3i m_CropsPos; cItemGrid m_Inventory; - -} ; - - - - +}; diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 8cf8aaae2..a49a8ab0d 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -42,7 +42,3 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) } AddRandomWeaponDropItem(a_Drops, LootingLevel); } - - - - diff --git a/src/Mobs/Witch.h b/src/Mobs/Witch.h index 44f4ba271..4134230fb 100644 --- a/src/Mobs/Witch.h +++ b/src/Mobs/Witch.h @@ -7,22 +7,16 @@ -class cWitch: - public cAggressiveMonster +class cWitch : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cWitch(); CLASS_PROTODEF(cWitch) virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; - bool IsAngry(void) const {return ((m_EMState == ATTACKING) || (m_EMState == CHASING)); } -} ; - - - - + bool IsAngry(void) const { return ((m_EMState == ATTACKING) || (m_EMState == CHASING)); } +}; diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index 87f5e170d..2d2f87992 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -77,7 +77,8 @@ void cWither::KilledBy(TakeDamageInfo & a_TDI) Super::KilledBy(a_TDI); Vector3d Pos = GetPosition(); - m_World->ForEachPlayer([=](cPlayer & a_Player) + m_World->ForEachPlayer( + [=](cPlayer & a_Player) { // TODO 2014-05-21 xdot: Vanilla minecraft uses an AABB check instead of a radius one double Dist = (a_Player.GetPosition() - Pos).Length(); @@ -100,7 +101,16 @@ void cWither::SpawnOn(cClientHandle & a_Client) Super::SpawnOn(a_Client); // Purple boss bar with no divisions that darkens the sky: - a_Client.SendBossBarAdd(GetUniqueID(), cCompositeChat("Wither"), GetHealth() / GetMaxHealth(), BossBarColor::Purple, BossBarDivisionType::None, true, false, false); + a_Client.SendBossBarAdd( + GetUniqueID(), + cCompositeChat("Wither"), + GetHealth() / GetMaxHealth(), + BossBarColor::Purple, + BossBarDivisionType::None, + true, + false, + false + ); } diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index f6afb1e6d..8eb634dd9 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -7,13 +7,11 @@ -class cWither: - public cAggressiveMonster +class cWither : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cWither(); CLASS_PROTODEF(cWither) @@ -33,9 +31,8 @@ public: virtual void SpawnOn(cClientHandle & a_Client) override; virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; -private: - - /** The number of ticks of invulnerability left after being initially created. Zero once invulnerability has expired. */ + private: + /** The number of ticks of invulnerability left after being initially created. Zero once invulnerability has + * expired. */ unsigned int m_WitherInvulnerableTicks; - -} ; +}; diff --git a/src/Mobs/WitherSkeleton.cpp b/src/Mobs/WitherSkeleton.cpp index e2acd8036..7d800e56f 100644 --- a/src/Mobs/WitherSkeleton.cpp +++ b/src/Mobs/WitherSkeleton.cpp @@ -9,7 +9,15 @@ cWitherSkeleton::cWitherSkeleton(void) : - Super("WitherSkeleton", mtWitherSkeleton, "entity.wither_skeleton.hurt", "entity.wither_skeleton.death", "entity.wither_skeleton.ambient", 0.7f, 2.4f) + Super( + "WitherSkeleton", + mtWitherSkeleton, + "entity.wither_skeleton.hurt", + "entity.wither_skeleton.death", + "entity.wither_skeleton.ambient", + 0.7f, + 2.4f + ) { } diff --git a/src/Mobs/WitherSkeleton.h b/src/Mobs/WitherSkeleton.h index 8aa7574df..c4a710bbf 100644 --- a/src/Mobs/WitherSkeleton.h +++ b/src/Mobs/WitherSkeleton.h @@ -7,21 +7,18 @@ -class cWitherSkeleton: - public cAggressiveMonster +class cWitherSkeleton : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cWitherSkeleton(); CLASS_PROTODEF(cWitherSkeleton) -private: - + private: virtual bool Attack(std::chrono::milliseconds a_Dt) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool IsNetherNative(void) override { return true; } virtual void SpawnOn(cClientHandle & a_ClientHandle) override; -} ; +}; diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 553ca1c73..45647ffba 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -42,14 +42,14 @@ bool cWolf::DoTakeDamage(TakeDamageInfo & a_TDI) { if (m_IsTame) { - if ((static_cast<cPlayer*>(currTarget)->GetUUID() == m_OwnerUUID)) + if ((static_cast<cPlayer *>(currTarget)->GetUUID() == m_OwnerUUID)) { SetTarget(PreviousTarget); // Do not attack owner } else { SetIsSitting(false); - NotifyAlliesOfFight(static_cast<cPawn*>(a_TDI.Attacker)); + NotifyAlliesOfFight(static_cast<cPawn *>(a_TDI.Attacker)); } } else @@ -60,7 +60,7 @@ bool cWolf::DoTakeDamage(TakeDamageInfo & a_TDI) else if (m_IsTame) { SetIsSitting(false); - NotifyAlliesOfFight(static_cast<cPawn*>(a_TDI.Attacker)); + NotifyAlliesOfFight(static_cast<cPawn *>(a_TDI.Attacker)); } } @@ -80,7 +80,9 @@ void cWolf::NotifyAlliesOfFight(cPawn * a_Opponent) } m_NotificationCooldown = 15; - m_World->DoWithPlayerByUUID(m_OwnerUUID, [=](cPlayer & a_Player) + m_World->DoWithPlayerByUUID( + m_OwnerUUID, + [=](cPlayer & a_Player) { a_Player.NotifyNearbyWolves(a_Opponent, false); return false; @@ -105,9 +107,8 @@ bool cWolf::Attack(std::chrono::milliseconds a_Dt) } } - NotifyAlliesOfFight(static_cast<cPawn*>(GetTarget())); + NotifyAlliesOfFight(static_cast<cPawn *>(GetTarget())); return Super::Attack(a_Dt); - } @@ -116,10 +117,7 @@ bool cWolf::Attack(std::chrono::milliseconds a_Dt) void cWolf::ReceiveNearbyFightInfo(const cUUID & a_PlayerID, cPawn * a_Opponent, bool a_IsPlayerInvolved) { - if ( - (a_Opponent == nullptr) || IsSitting() || (!IsTame()) || - (!a_Opponent->IsPawn()) || (a_PlayerID != m_OwnerUUID) - ) + if ((a_Opponent == nullptr) || IsSitting() || (!IsTame()) || (!a_Opponent->IsPawn()) || (a_PlayerID != m_OwnerUUID)) { return; } @@ -156,8 +154,6 @@ void cWolf::ReceiveNearbyFightInfo(const cUUID & a_PlayerID, cPawn * a_Opponent, } SetTarget(a_Opponent); - - } @@ -263,9 +259,9 @@ void cWolf::OnRightClicked(cPlayer & a_Player) if ((EquippedItemType == E_ITEM_SPAWN_EGG) && (!IsTame())) { eMonsterType MonsterType = cItemSpawnEggHandler::ItemDamageToMonsterType(EquippedItem.m_ItemDamage); - if ( - (MonsterType == m_MobType) && - (m_World->SpawnMob(GetPosX(), GetPosY(), GetPosZ(), m_MobType, true) != cEntity::INVALID_ID)) // Spawning succeeded + if ((MonsterType == m_MobType) && + (m_World->SpawnMob(GetPosX(), GetPosY(), GetPosZ(), m_MobType, true) != cEntity::INVALID_ID + )) // Spawning succeeded { if (!a_Player.IsGameModeCreative()) { @@ -305,47 +301,51 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) if (GetTarget() == nullptr) { - m_World->DoWithNearestPlayer(GetPosition(), static_cast<float>(m_SightDistance), [&](cPlayer & a_Player) -> bool - { - switch (a_Player.GetEquippedItem().m_ItemType) + m_World->DoWithNearestPlayer( + GetPosition(), + static_cast<float>(m_SightDistance), + [&](cPlayer & a_Player) -> bool { - case E_ITEM_BONE: - case E_ITEM_RAW_BEEF: - case E_ITEM_STEAK: - case E_ITEM_RAW_CHICKEN: - case E_ITEM_COOKED_CHICKEN: - case E_ITEM_ROTTEN_FLESH: - case E_ITEM_RAW_PORKCHOP: - case E_ITEM_COOKED_PORKCHOP: + switch (a_Player.GetEquippedItem().m_ItemType) { - if (!IsBegging()) + case E_ITEM_BONE: + case E_ITEM_RAW_BEEF: + case E_ITEM_STEAK: + case E_ITEM_RAW_CHICKEN: + case E_ITEM_COOKED_CHICKEN: + case E_ITEM_ROTTEN_FLESH: + case E_ITEM_RAW_PORKCHOP: + case E_ITEM_COOKED_PORKCHOP: { - SetIsBegging(true); - m_World->BroadcastEntityMetadata(*this); - } + if (!IsBegging()) + { + SetIsBegging(true); + m_World->BroadcastEntityMetadata(*this); + } - m_FinalDestination = a_Player.GetPosition(); // So that we will look at a player holding food + m_FinalDestination = a_Player.GetPosition(); // So that we will look at a player holding food - // Don't move to the player if the wolf is sitting. - if (!IsSitting()) - { - MoveToPosition(a_Player.GetPosition()); - } + // Don't move to the player if the wolf is sitting. + if (!IsSitting()) + { + MoveToPosition(a_Player.GetPosition()); + } - break; - } - default: - { - if (IsBegging()) + break; + } + default: { - SetIsBegging(false); - m_World->BroadcastEntityMetadata(*this); + if (IsBegging()) + { + SetIsBegging(false); + m_World->BroadcastEntityMetadata(*this); + } } } - } - return true; - }); + return true; + } + ); } else { diff --git a/src/Mobs/Wolf.h b/src/Mobs/Wolf.h index d3b689ef3..71e214f36 100644 --- a/src/Mobs/Wolf.h +++ b/src/Mobs/Wolf.h @@ -9,13 +9,11 @@ class cEntity; -class cWolf: - public cPassiveAggressiveMonster +class cWolf : public cPassiveAggressiveMonster { using Super = cPassiveAggressiveMonster; -public: - + public: cWolf(); CLASS_PROTODEF(cWolf) @@ -28,21 +26,21 @@ public: virtual bool Attack(std::chrono::milliseconds a_Dt) override; // Get functions - bool IsSitting (void) const override { return m_IsSitting; } - bool IsTame (void) const override { return m_IsTame; } - bool IsBegging (void) const { return m_IsBegging; } - bool IsAngry (void) const { return m_IsAngry; } - AString GetOwnerName (void) const { return m_OwnerName; } - cUUID GetOwnerUUID (void) const { return m_OwnerUUID; } - int GetCollarColor(void) const { return m_CollarColor; } + bool IsSitting(void) const override { return m_IsSitting; } + bool IsTame(void) const override { return m_IsTame; } + bool IsBegging(void) const { return m_IsBegging; } + bool IsAngry(void) const { return m_IsAngry; } + AString GetOwnerName(void) const { return m_OwnerName; } + cUUID GetOwnerUUID(void) const { return m_OwnerUUID; } + int GetCollarColor(void) const { return m_CollarColor; } // Set functions - void SetIsSitting (bool a_IsSitting) { m_IsSitting = a_IsSitting; } - void SetIsTame (bool a_IsTame) { m_IsTame = a_IsTame; } - void SetIsBegging (bool a_IsBegging) { m_IsBegging = a_IsBegging; } - void SetIsAngry (bool a_IsAngry) { m_IsAngry = a_IsAngry; } - void SetCollarColor(int a_CollarColor) { m_CollarColor = a_CollarColor; } - void SetOwner (const AString & a_NewOwnerName, const cUUID & a_NewOwnerUUID) + void SetIsSitting(bool a_IsSitting) { m_IsSitting = a_IsSitting; } + void SetIsTame(bool a_IsTame) { m_IsTame = a_IsTame; } + void SetIsBegging(bool a_IsBegging) { m_IsBegging = a_IsBegging; } + void SetIsAngry(bool a_IsAngry) { m_IsAngry = a_IsAngry; } + void SetCollarColor(int a_CollarColor) { m_CollarColor = a_CollarColor; } + void SetOwner(const AString & a_NewOwnerName, const cUUID & a_NewOwnerUUID) { m_OwnerName = a_NewOwnerName; m_OwnerUUID = a_NewOwnerUUID; @@ -76,18 +74,13 @@ public: } -protected: - - bool m_IsSitting; - bool m_IsTame; - bool m_IsBegging; - bool m_IsAngry; + protected: + bool m_IsSitting; + bool m_IsTame; + bool m_IsBegging; + bool m_IsAngry; AString m_OwnerName; - cUUID m_OwnerUUID; - int m_CollarColor; - int m_NotificationCooldown; -} ; - - - - + cUUID m_OwnerUUID; + int m_CollarColor; + int m_NotificationCooldown; +}; diff --git a/src/Mobs/Zombie.h b/src/Mobs/Zombie.h index 111847ea3..940e22d78 100644 --- a/src/Mobs/Zombie.h +++ b/src/Mobs/Zombie.h @@ -6,22 +6,15 @@ -class cZombie: - public cAggressiveMonster +class cZombie : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cZombie(); CLASS_PROTODEF(cZombie) virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool IsUndead(void) override { return true; } - -} ; - - - - +}; diff --git a/src/Mobs/ZombiePigman.cpp b/src/Mobs/ZombiePigman.cpp index 755f585ab..b26350075 100644 --- a/src/Mobs/ZombiePigman.cpp +++ b/src/Mobs/ZombiePigman.cpp @@ -9,7 +9,15 @@ cZombiePigman::cZombiePigman(void) : - Super("ZombiePigman", mtZombiePigman, "entity.zombie_pig.hurt", "entity.zombie_pig.death", "entity.zombie_pig.ambient", 0.6f, 1.95f) + Super( + "ZombiePigman", + mtZombiePigman, + "entity.zombie_pig.hurt", + "entity.zombie_pig.death", + "entity.zombie_pig.ambient", + 0.6f, + 1.95f + ) { } diff --git a/src/Mobs/ZombiePigman.h b/src/Mobs/ZombiePigman.h index 93535a3ce..7ccff687e 100644 --- a/src/Mobs/ZombiePigman.h +++ b/src/Mobs/ZombiePigman.h @@ -6,22 +6,19 @@ -class cZombiePigman: - public cPassiveAggressiveMonster +class cZombiePigman : public cPassiveAggressiveMonster { using Super = cPassiveAggressiveMonster; -public: - + public: cZombiePigman(); CLASS_PROTODEF(cZombiePigman) -private: - + private: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool IsUndead(void) override { return true; } virtual bool IsNetherNative(void) override { return true; } virtual void KilledBy(TakeDamageInfo & a_TDI) override; virtual void SpawnOn(cClientHandle & a_ClientHandle) override; -} ; +}; diff --git a/src/Mobs/ZombieVillager.cpp b/src/Mobs/ZombieVillager.cpp index cde099947..ae7ad96ca 100644 --- a/src/Mobs/ZombieVillager.cpp +++ b/src/Mobs/ZombieVillager.cpp @@ -11,7 +11,15 @@ cZombieVillager::cZombieVillager(cVillager::eVillagerType a_Profession) : - Super("ZombieVillager", mtZombieVillager, "entity.zombie_villager.hurt", "entity.zombie_villager.death", "entity.ambient", 0.6f, 1.95f), + Super( + "ZombieVillager", + mtZombieVillager, + "entity.zombie_villager.hurt", + "entity.zombie_villager.death", + "entity.ambient", + 0.6f, + 1.95f + ), m_ConversionTime(-1), m_Profession(a_Profession) { diff --git a/src/Mobs/ZombieVillager.h b/src/Mobs/ZombieVillager.h index 2a3e67959..989d86e8c 100644 --- a/src/Mobs/ZombieVillager.h +++ b/src/Mobs/ZombieVillager.h @@ -7,28 +7,24 @@ -class cZombieVillager: - public cAggressiveMonster +class cZombieVillager : public cAggressiveMonster { using Super = cAggressiveMonster; -public: - + public: cZombieVillager(cVillager::eVillagerType a_Profession); CLASS_PROTODEF(cZombieVillager) - virtual void GetDrops (cItems & a_Drops, cEntity * a_Killer = nullptr) override; - virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void OnRightClicked (cPlayer & a_Player) override; - virtual bool IsUndead (void) override { return true; } - - int ConversionTime (void) const { return m_ConversionTime; } - cVillager::eVillagerType GetProfession (void) const { return m_Profession; } + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + virtual void OnRightClicked(cPlayer & a_Player) override; + virtual bool IsUndead(void) override { return true; } -private: + int ConversionTime(void) const { return m_ConversionTime; } + cVillager::eVillagerType GetProfession(void) const { return m_Profession; } + private: int m_ConversionTime; cVillager::eVillagerType m_Profession; - -} ; +}; |