diff options
Diffstat (limited to 'src/Mobs')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttacker.cpp | 1 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerRanged.cpp | 24 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerRanged.h | 11 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp | 44 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h | 15 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorCoward.cpp | 4 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorWanderer.cpp | 4 | ||||
-rw-r--r-- | src/Mobs/Behaviors/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/Mobs/Creeper.cpp | 40 | ||||
-rw-r--r-- | src/Mobs/Creeper.h | 1 | ||||
-rw-r--r-- | src/Mobs/Monster.h | 9 | ||||
-rw-r--r-- | src/Mobs/Skeleton.cpp | 31 | ||||
-rw-r--r-- | src/Mobs/Skeleton.h | 14 | ||||
-rw-r--r-- | src/Mobs/Zombie.cpp | 1 | ||||
-rw-r--r-- | src/Mobs/Zombie.h | 2 |
15 files changed, 124 insertions, 81 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAttacker.cpp b/src/Mobs/Behaviors/BehaviorAttacker.cpp index 2f25bd3aa..280914f09 100644 --- a/src/Mobs/Behaviors/BehaviorAttacker.cpp +++ b/src/Mobs/Behaviors/BehaviorAttacker.cpp @@ -99,6 +99,7 @@ void cBehaviorAttacker::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (TargetIsInStrikeRadiusAndLineOfSight()) { + m_Parent->StopMovingToPosition(); StrikeTargetIfReady(); } else diff --git a/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp b/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp new file mode 100644 index 000000000..389c6b9f7 --- /dev/null +++ b/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp @@ -0,0 +1,24 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "BehaviorAttackerRanged.h" +#include "../Monster.h" +#include "../../Entities/Pawn.h" +#include "../../BlockID.h" +#include "../../Entities/ArrowEntity.h" + +bool cBehaviorAttackerRanged::StrikeTarget(int a_StrikeTickCnt) +{ + UNUSED(a_StrikeTickCnt); + auto & Random = GetRandomProvider(); + 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 Speed = (GetTarget()->GetPosition() + Inaccuracy - m_Parent->GetPosition()) * 5; + Speed.y += Random.RandInt(-1, 1); + + auto Arrow = cpp14::make_unique<cArrowEntity>(m_Parent, m_Parent->GetPosX(), m_Parent->GetPosY() + 1, m_Parent->GetPosZ(), Speed); + auto ArrowPtr = Arrow.get(); + ArrowPtr->Initialize(std::move(Arrow), *m_Parent->GetWorld()); + } + return true; // Finish the strike. It only takes 1 tick. +} diff --git a/src/Mobs/Behaviors/BehaviorAttackerRanged.h b/src/Mobs/Behaviors/BehaviorAttackerRanged.h new file mode 100644 index 000000000..9ccf4b2d6 --- /dev/null +++ b/src/Mobs/Behaviors/BehaviorAttackerRanged.h @@ -0,0 +1,11 @@ +#pragma once + +#include "BehaviorAttacker.h" + +/** Grants the mob that ability to approach a target and then melee attack it. +Use BehaviorAttackerMelee::SetTarget to attack. */ +class cBehaviorAttackerRanged : public cBehaviorAttacker +{ +public: + bool StrikeTarget(int a_StrikeTickCnt) override; +}; diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp new file mode 100644 index 000000000..a2ca50e5f --- /dev/null +++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp @@ -0,0 +1,44 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "BehaviorAttackerSuicideBomber.h" +#include "../Monster.h" +#include "../../Entities/Pawn.h" +#include "../../BlockID.h" + +bool cBehaviorAttackerSuicideBomber::StrikeTarget(int a_StrikeTickCnt) +{ + UNUSED(a_StrikeTickCnt); + //mobTodo + return true; // Finish the strike. It only takes 1 tick. +} + +/* + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } + + if (((GetTarget() == nullptr) || !TargetIsInRange()) && !m_BurnedWithFlintAndSteel) + { + if (m_bIsBlowing) + { + m_ExplodingTimer = 0; + m_bIsBlowing = false; + m_World->BroadcastEntityMetadata(*this); + } + } + else + { + if (m_bIsBlowing) + { + m_ExplodingTimer += 1; + } + + if ((m_ExplodingTimer == 30) && (GetHealth() > 0.0)) // only explode when not already dead + { + m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this); + Destroy(); // Just in case we aren't killed by the explosion + } + } + */ diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h new file mode 100644 index 000000000..dc071e2f4 --- /dev/null +++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h @@ -0,0 +1,15 @@ +#pragma once + +#include "BehaviorAttacker.h" + +/** Grants the mob that ability to approach a target and then melee attack it. +Use BehaviorAttackerMelee::SetTarget to attack. */ +class cBehaviorAttackerSuicideBomber : public cBehaviorAttacker +{ +public: + bool StrikeTarget(int a_StrikeTickCnt) override; + void OnRightClicked(cPlayer & a_Player) override; + +private: + +}; diff --git a/src/Mobs/Behaviors/BehaviorCoward.cpp b/src/Mobs/Behaviors/BehaviorCoward.cpp index 55a5932cd..fc13cf5b9 100644 --- a/src/Mobs/Behaviors/BehaviorCoward.cpp +++ b/src/Mobs/Behaviors/BehaviorCoward.cpp @@ -40,7 +40,7 @@ bool cBehaviorCoward::ControlStarting(std::chrono::milliseconds a_Dt, cChunk & a { UNUSED(a_Dt); UNUSED(a_Chunk); - m_Parent->GetPathFinder().setDontCare(true); // We don't care we're we are going when + m_Parent->GetPathFinder().SetDontCare(true); // We don't care we're we are going when // wandering. If a path is not found, the pathfinder just modifies our destination. m_Parent->SetRelativeWalkSpeed(m_Parent->GetRelativeWalkSpeed() * 3); return true; @@ -52,7 +52,7 @@ bool cBehaviorCoward::ControlEnding(std::chrono::milliseconds a_Dt, cChunk & a_C UNUSED(a_Dt); UNUSED(a_Chunk); m_Parent->SetRelativeWalkSpeed(m_Parent->GetRelativeWalkSpeed() / 3); - m_Parent->GetPathFinder().setDontCare(false); + m_Parent->GetPathFinder().SetDontCare(false); return true; } diff --git a/src/Mobs/Behaviors/BehaviorWanderer.cpp b/src/Mobs/Behaviors/BehaviorWanderer.cpp index cc03d55cb..56316bd9f 100644 --- a/src/Mobs/Behaviors/BehaviorWanderer.cpp +++ b/src/Mobs/Behaviors/BehaviorWanderer.cpp @@ -39,7 +39,7 @@ bool cBehaviorWanderer::ControlStarting(std::chrono::milliseconds a_Dt, cChunk & { UNUSED(a_Dt); UNUSED(a_Chunk); - m_Parent->GetPathFinder().setDontCare(true); // We don't care we're we are going when + m_Parent->GetPathFinder().SetDontCare(true); // We don't care we're we are going when // wandering. If a path is not found, the pathfinder just modifies our destination. return true; } @@ -49,7 +49,7 @@ bool cBehaviorWanderer::ControlEnding(std::chrono::milliseconds a_Dt, cChunk & a { UNUSED(a_Dt); UNUSED(a_Chunk); - m_Parent->GetPathFinder().setDontCare(false); + m_Parent->GetPathFinder().SetDontCare(false); return true; } diff --git a/src/Mobs/Behaviors/CMakeLists.txt b/src/Mobs/Behaviors/CMakeLists.txt index e92c850e3..f205e9cb4 100644 --- a/src/Mobs/Behaviors/CMakeLists.txt +++ b/src/Mobs/Behaviors/CMakeLists.txt @@ -17,6 +17,8 @@ SET (SRCS BehaviorItemFollower.cpp BehaviorItemReplacer.cpp BehaviorAttackerMelee.cpp + BehaviorAttackerRanged.cpp + BehaviorAttackerSuicideBomber.cpp BehaviorWanderer.cpp ) @@ -33,6 +35,8 @@ SET (HDRS BehaviorItemFollower.h BehaviorItemReplacer.h BehaviorAttackerMelee.h + BehaviorAttackerRanged.h + BehaviorAttackerSuicideBomber.h BehaviorWanderer.h ) diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 042db9686..3c43cc523 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -25,46 +25,6 @@ cCreeper::cCreeper(void) : -void cCreeper::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) -{ - super::Tick(a_Dt, a_Chunk); - /* mobTodo - - if (!IsTicking()) - { - // The base class tick destroyed us - return; - } - - if (((GetTarget() == nullptr) || !TargetIsInRange()) && !m_BurnedWithFlintAndSteel) - { - if (m_bIsBlowing) - { - m_ExplodingTimer = 0; - m_bIsBlowing = false; - m_World->BroadcastEntityMetadata(*this); - } - } - else - { - if (m_bIsBlowing) - { - m_ExplodingTimer += 1; - } - - if ((m_ExplodingTimer == 30) && (GetHealth() > 0.0)) // only explode when not already dead - { - m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this); - Destroy(); // Just in case we aren't killed by the explosion - } - } */ - -} - - - - - void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { if (m_ExplodingTimer == 30) diff --git a/src/Mobs/Creeper.h b/src/Mobs/Creeper.h index 28a0dd512..8e74160dc 100644 --- a/src/Mobs/Creeper.h +++ b/src/Mobs/Creeper.h @@ -19,7 +19,6 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; - 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; } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index be3d64e06..f8cac4e7a 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -68,6 +68,12 @@ public: /** Engage pathfinder and tell it to calculate a path to a given position, and move the mob accordingly. */ virtual void MoveToPosition(const Vector3d & a_Position); // tolua_export + // mobTodo - MoveToPosition export is probably broken. The AI will keep overriding the + // destination. + + /** Stops pathfinding. Calls ResetPathFinding and sets m_IsFollowingPath to false */ + void StopMovingToPosition(); + // tolua_begin eMonsterType GetMobType(void) const { return m_MobType; } eFamily GetMobFamily(void) const; @@ -267,9 +273,6 @@ protected: /** Move in a straight line to the next waypoint in the path, will jump if needed. */ void MoveToWayPoint(cChunk & a_Chunk); - /** Stops pathfinding. Calls ResetPathFinding and sets m_IsFollowingPath to false */ - void StopMovingToPosition(); - /** Sets the body yaw and head yaw */ void SetPitchAndYawFromDestination(bool a_IsFollowingPath); diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 69e3e0f55..fe7c6182e 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -14,6 +14,10 @@ cSkeleton::cSkeleton(bool IsWither) : m_bIsWither(IsWither) { m_EMPersonality = AGGRESSIVE; + m_BehaviorAttackerRanged.AttachToMonster(*this); + m_BehaviorWanderer.AttachToMonster(*this); + m_BehaviorAggressive.AttachToMonster(*this); + m_BehaviourDayLightBurner.AttachToMonster(*this); GetMonsterConfig("Skeleton"); } @@ -48,33 +52,6 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) -//mobTodo -/*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 - auto & Random = GetRandomProvider(); - 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 Speed = (GetTarget()->GetPosition() + Inaccuracy - GetPosition()) * 5; - Speed.y += Random.RandInt(-1, 1); - - auto Arrow = cpp14::make_unique<cArrowEntity>(this, GetPosX(), GetPosY() + 1, GetPosZ(), Speed); - auto ArrowPtr = Arrow.get(); - if (!ArrowPtr->Initialize(std::move(Arrow), *m_World)) - { - return false; - } - - ResetAttackCooldown(); - return true; - } - return false; -}*/ - - - - void cSkeleton::SpawnOn(cClientHandle & a_ClientHandle) { diff --git a/src/Mobs/Skeleton.h b/src/Mobs/Skeleton.h index 56e7339e0..59277729b 100644 --- a/src/Mobs/Skeleton.h +++ b/src/Mobs/Skeleton.h @@ -2,9 +2,10 @@ #pragma once #include "Monster.h" - - - +#include "Behaviors/BehaviorAttackerRanged.h" +#include "Behaviors/BehaviorWanderer.h" +#include "Behaviors/BehaviorAggressive.h" +#include "Behaviors/BehaviorDayLightBurner.h" class cSkeleton : @@ -29,6 +30,13 @@ private: bool m_bIsWither; + // tick behaviors + cBehaviorAttackerRanged m_BehaviorAttackerRanged; + cBehaviorWanderer m_BehaviorWanderer; + + // other behaviors + cBehaviorAggressive m_BehaviorAggressive; + cBehaviorDayLightBurner m_BehaviourDayLightBurner; } ; diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 7a74e46e1..085d90b7f 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -15,7 +15,6 @@ cZombie::cZombie(bool a_IsVillagerZombie) : m_IsConverting(false) { m_EMPersonality = AGGRESSIVE; - m_BehaviorAttackerMelee.AttachToMonster(*this); m_BehaviorWanderer.AttachToMonster(*this); m_BehaviorAggressive.AttachToMonster(*this); diff --git a/src/Mobs/Zombie.h b/src/Mobs/Zombie.h index 1bb2ebd45..5c2c225e4 100644 --- a/src/Mobs/Zombie.h +++ b/src/Mobs/Zombie.h @@ -1,10 +1,8 @@ #pragma once #include "Monster.h" - #include "Behaviors/BehaviorAttackerMelee.h" #include "Behaviors/BehaviorWanderer.h" - #include "Behaviors/BehaviorAggressive.h" #include "Behaviors/BehaviorDayLightBurner.h" |