diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorDayLightBurner.cpp | 19 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorDayLightBurner.h | 8 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorItemFollower.cpp | 1 | ||||
-rw-r--r-- | src/Mobs/Monster.cpp | 80 | ||||
-rw-r--r-- | src/Mobs/Monster.h | 5 | ||||
-rw-r--r-- | src/Mobs/Skeleton.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/Zombie.cpp | 34 |
7 files changed, 43 insertions, 106 deletions
diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp b/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp index 9f182a359..809f0190f 100644 --- a/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp +++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp @@ -2,10 +2,11 @@ #include "BehaviorDayLightBurner.h" #include "../Monster.h" -#include "../../World.h" #include "../../Entities/Player.h" #include "../../Entities/Entity.h" +#include "../../Chunk.h" + cBehaviorDayLightBurner::cBehaviorDayLightBurner(cMonster * a_Parent) : m_Parent(a_Parent) { ASSERT(m_Parent != nullptr); @@ -13,7 +14,7 @@ cBehaviorDayLightBurner::cBehaviorDayLightBurner(cMonster * a_Parent) : m_Parent void cBehaviorDayLightBurner::Tick(cChunk & a_Chunk, bool WouldBurn) { - int RelY = POSY_TOINT; + int RelY = static_cast<int>(m_Parent->GetPosY()); if ((RelY < 0) || (RelY >= cChunkDef::Height)) { // Outside the world @@ -21,21 +22,21 @@ void cBehaviorDayLightBurner::Tick(cChunk & a_Chunk, bool WouldBurn) } if (!a_Chunk.IsLightValid()) { - m_World->QueueLightChunk(GetChunkX(), GetChunkZ()); + m_Parent->GetWorld()->QueueLightChunk(m_Parent->GetChunkX(), m_Parent->GetChunkZ()); return; } - if (!IsOnFire() && WouldBurn) + if (!m_Parent->IsOnFire() && WouldBurn) { // Burn for 100 ticks, then decide again - StartBurning(100); + m_Parent->StartBurning(100); } } -bool cBehaviorDayLightBurner::WouldBurnAt(Vector3d & a_Location, cChunk & a_Chunk) +bool cBehaviorDayLightBurner::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk) { int RelY = FloorC(a_Location.y); if (RelY <= 0) @@ -57,11 +58,11 @@ bool cBehaviorDayLightBurner::WouldBurnAt(Vector3d & a_Location, cChunk & a_Chun if ( (Chunk->GetBlock(Rel.x, Rel.y, Rel.z) != E_BLOCK_SOULSAND) && // Not on soulsand - (GetWorld()->GetTimeOfDay() < 12000 + 1000) && // Daytime - GetWorld()->IsWeatherSunnyAt(POSX_TOINT, POSZ_TOINT) // Not raining + (m_Parent->GetWorld()->GetTimeOfDay() < 12000 + 1000) && // Daytime + m_Parent->GetWorld()->IsWeatherSunnyAt(static_cast<int>(m_Parent->GetPosX()), static_cast<int>(m_Parent->GetPosZ())) // Not raining ) { - int MobHeight = static_cast<int>(a_Location.y) + round(GetHeight()) - 1; // The height of the mob head + int MobHeight = static_cast<int>(a_Location.y) + static_cast<int>(round(m_Parent->GetHeight())) - 1; // The height of the mob head if (MobHeight >= cChunkDef::Height) { return true; diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.h b/src/Mobs/Behaviors/BehaviorDayLightBurner.h index b54a863af..d967b5f68 100644 --- a/src/Mobs/Behaviors/BehaviorDayLightBurner.h +++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.h @@ -1,16 +1,20 @@ #pragma once +// mobTodo I just need vector3d +#include "../../World.h" + // fwds class cMonster; class cEntity; class cChunk; -class Vector3d; class cBehaviorDayLightBurner { +public: cBehaviorDayLightBurner(cMonster * a_Parent); - bool WouldBurnAt(Vector3d & a_Location, cChunk & a_Chunk); + void Tick(cChunk & a_Chunk, bool WouldBurn); + bool WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk); // Functions our host Monster should invoke: void Tick(); diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.cpp b/src/Mobs/Behaviors/BehaviorItemFollower.cpp index 9d64ee0db..833050e69 100644 --- a/src/Mobs/Behaviors/BehaviorItemFollower.cpp +++ b/src/Mobs/Behaviors/BehaviorItemFollower.cpp @@ -19,7 +19,6 @@ cBehaviorItemFollower::cBehaviorItemFollower(cMonster * a_Parent) : bool cBehaviorItemFollower::ActiveTick() { - cWorld * World = m_Parent->GetWorld(); cItems FollowedItems; m_Parent->GetFollowedItems(FollowedItems); if (FollowedItems.Size() > 0) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index fe2809f28..9afdce562 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -19,6 +19,9 @@ #include "PathFinder.h" #include "../Entities/LeashKnot.h" +// Temporary pathfinder hack +#include "Behaviors/BehaviorDayLightBurner.h" + @@ -326,9 +329,6 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } } - // Process the undead burning in daylight. - HandleDaylightBurning(*Chunk, WouldBurnAt(GetPosition(), *Chunk)); - bool a_IsFollowingPath = false; if (m_PathfinderActivated) { @@ -348,9 +348,9 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) 2. I was not hurt by a player recently. Then STOP. */ if ( - (GetBehaviorDaylightBurner() != nullptr) && ((m_TicksSinceLastDamaged >= 100) || (m_EMState == IDLE)) && - WouldBurnAt(m_NextWayPointPosition, *Chunk) && - !WouldBurnAt(GetPosition(), *Chunk) + (GetBehaviorDayLightBurner() != nullptr) && ((m_TicksSinceLastDamaged >= 100) || (m_EMState == IDLE)) && + GetBehaviorDayLightBurner()->WouldBurnAt(m_NextWayPointPosition, *Chunk) && + !(GetBehaviorDayLightBurner()->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: @@ -1177,7 +1177,7 @@ cBehaviorWanderer * cMonster::GetBehaviorWanderer() -cBehaviorWanderer * cMonster::GetBehaviorDaylightBurner() +cBehaviorDayLightBurner * cMonster::GetBehaviorDayLightBurner() { return nullptr; } @@ -1422,72 +1422,6 @@ void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, unsigned int a_LootingL -bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk) -{ - // If the Y coord is out of range, return the most logical result without considering anything else: - int RelY = FloorC(a_Location.y); - if (RelY < 0) - { - // Never burn under the world - return false; - } - if (RelY >= cChunkDef::Height) - { - // Always burn above the world - return true; - } - if (RelY <= 0) - { - // The mob is about to die, no point in burning - return false; - } - - PREPARE_REL_AND_CHUNK(a_Location, a_Chunk); - if (!RelSuccess) - { - return false; - } - - if ( - (Chunk->GetBlock(Rel.x, Rel.y, Rel.z) != E_BLOCK_SOULSAND) && // Not on soulsand - (GetWorld()->GetTimeOfDay() < 12000 + 1000) && // Daytime - GetWorld()->IsWeatherSunnyAt(POSX_TOINT, POSZ_TOINT) // Not raining - ) - { - int MobHeight = FloorC(a_Location.y + GetHeight()) - 1; // The block Y coord of the mob's head - if (MobHeight >= cChunkDef::Height) - { - return true; - } - // Start with the highest block and scan down to 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). - int CurrentBlock = Chunk->GetHeight(Rel.x, Rel.z); - while (CurrentBlock >= MobHeight) - { - BLOCKTYPE Block = Chunk->GetBlock(Rel.x, CurrentBlock, Rel.z); - if ( - // Do not burn if a block above us meets one of the following conditions: - (!cBlockInfo::IsTransparent(Block)) || - (Block == E_BLOCK_LEAVES) || - (Block == E_BLOCK_NEW_LEAVES) || - (IsBlockWater(Block)) - ) - { - return false; - } - --CurrentBlock; - } - return true; - - } - return false; -} - - - - cMonster::eFamily cMonster::GetMobFamily(void) const { diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 22c8dfded..13d1bb6a5 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -17,6 +17,7 @@ class cBehaviorBreeder; class cBehaviorChaser; class cBehaviorStriker; class cBehaviorWanderer; +class cBehaviorDayLightBurner; // tolua_begin class cMonster : @@ -225,7 +226,7 @@ public: virtual cBehaviorChaser * GetBehaviorChaser(); virtual cBehaviorStriker * GetBehaviorStriker(); virtual cBehaviorWanderer * GetBehaviorWanderer(); - virtual cBehaviorWanderer * GetBehaviorDaylightBurner(); + virtual cBehaviorDayLightBurner * GetBehaviorDayLightBurner(); // Polymorphic behavior functions ("Skin-specific") virtual void InheritFromParents(cMonster * a_Parent1, cMonster * a_Parent2); @@ -311,8 +312,6 @@ public: bool m_CanPickUpLoot; int m_TicksSinceLastDamaged; // How many ticks ago we were last damaged by a player? - void HandleDaylightBurning(cChunk & a_Chunk, bool WouldBurn); - bool WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk); double m_RelativeWalkSpeed; int m_Age; diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 22ea3e1bc..55616cc28 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -13,7 +13,7 @@ cSkeleton::cSkeleton(bool IsWither) : super("Skeleton", mtSkeleton, "entity.skeleton.hurt", "entity.skeleton.death", 0.6, 1.8), m_bIsWither(IsWither) { - SetBurnsInDaylight(true); + } diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 882e98bf1..6f889e182 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -10,11 +10,11 @@ cZombie::cZombie(bool a_IsVillagerZombie) : - super("Zombie", mtZombie, "entity.zombie.hurt", "entity.zombie.death", 0.6, 1.8), - m_IsVillagerZombie(a_IsVillagerZombie), - m_IsConverting(false) + super("Zombie", mtZombie, "entity.zombie.hurt", "entity.zombie.death", 0.6, 1.8), + m_IsVillagerZombie(a_IsVillagerZombie), + m_IsConverting(false) { - SetBurnsInDaylight(true); + } @@ -23,17 +23,17 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - unsigned int LootingLevel = 0; - if (a_Killer != nullptr) - { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); - } - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); - cItems RareDrops; - RareDrops.Add(cItem(E_ITEM_IRON)); - RareDrops.Add(cItem(E_ITEM_CARROT)); - RareDrops.Add(cItem(E_ITEM_POTATO)); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); - AddRandomArmorDropItem(a_Drops, LootingLevel); - AddRandomWeaponDropItem(a_Drops, LootingLevel); + unsigned int LootingLevel = 0; + if (a_Killer != nullptr) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_IRON)); + RareDrops.Add(cItem(E_ITEM_CARROT)); + RareDrops.Add(cItem(E_ITEM_POTATO)); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } |