summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Components/MovementComponent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs/Components/MovementComponent.cpp')
-rw-r--r--src/Mobs/Components/MovementComponent.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/Mobs/Components/MovementComponent.cpp b/src/Mobs/Components/MovementComponent.cpp
new file mode 100644
index 000000000..e808e2948
--- /dev/null
+++ b/src/Mobs/Components/MovementComponent.cpp
@@ -0,0 +1,50 @@
+#include "Globals.h"
+#include "MovementComponent.h"
+#include "../Monster.h"
+
+#include "../../World.h"
+
+cMovementComponent::cMovementComponent(cMonster * a_Entity) : m_Self(a_Entity){}
+
+
+int cMovementComponent::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
+{
+ int PosY = (int)floor(m_Self->GetPosY());
+ PosY = Clamp(PosY, 0, cChunkDef::Height);
+
+ if (!cBlockInfo::IsSolid(m_Self->GetWorld()->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))))
+ {
+ while (!cBlockInfo::IsSolid(m_Self->GetWorld()->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY > 0))
+ {
+ PosY--;
+ }
+
+ return PosY + 1;
+ }
+ else
+ {
+ while (cBlockInfo::IsSolid(m_Self->GetWorld()->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY < cChunkDef::Height))
+ {
+ PosY++;
+ }
+
+ return PosY;
+ }
+}
+
+
+
+
+
+bool cMovementComponent::IsNextYPosReachable(int a_PosY)
+{
+ return (
+ (a_PosY <= (int)floor(m_Self->GetPosY())) ||
+ DoesPosYRequireJump(a_PosY)
+ );
+}
+/** Returns if a monster can reach a given height by jumping */
+bool cMovementComponent::DoesPosYRequireJump(int a_PosY)
+{
+ return ((a_PosY > (int)floor(m_Self->GetPosY())) && (a_PosY == (int)floor(m_Self->GetPosY()) + 1));
+}