summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-11 23:09:56 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-11 23:09:56 +0100
commit06239c8336a340459a62b45b6d633a55058e4677 (patch)
tree18228a83e863488209da2f9cd18df9352cc1a29d /src/Mobs
parentFixed #612 (diff)
downloadcuberite-06239c8336a340459a62b45b6d633a55058e4677.tar
cuberite-06239c8336a340459a62b45b6d633a55058e4677.tar.gz
cuberite-06239c8336a340459a62b45b6d633a55058e4677.tar.bz2
cuberite-06239c8336a340459a62b45b6d633a55058e4677.tar.lz
cuberite-06239c8336a340459a62b45b6d633a55058e4677.tar.xz
cuberite-06239c8336a340459a62b45b6d633a55058e4677.tar.zst
cuberite-06239c8336a340459a62b45b6d633a55058e4677.zip
Diffstat (limited to 'src/Mobs')
-rw-r--r--src/Mobs/AggressiveMonster.cpp11
-rw-r--r--src/Mobs/AggressiveMonster.h2
-rw-r--r--src/Mobs/Monster.cpp14
-rw-r--r--src/Mobs/Monster.h2
4 files changed, 10 insertions, 19 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index f2f0c404c..7da9f4fc2 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -5,7 +5,7 @@
#include "../World.h"
#include "../Entities/Player.h"
-#include "../MersenneTwister.h"
+#include "../Tracer.h"
@@ -73,6 +73,13 @@ void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
{
CheckEventSeePlayer();
}
+
+ cTracer LineOfSight(GetWorld());
+ if (ReachedFinalDestination() && (m_Target != NULL) && !LineOfSight.Trace(GetPosition(), (m_Target->GetPosition() - GetPosition()), (int)(m_Target->GetPosition() - GetPosition()).Length()))
+ {
+ // 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 / 1000);
+ }
}
@@ -81,7 +88,7 @@ void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
void cAggressiveMonster::Attack(float a_Dt)
{
- super::Attack(a_Dt);
+ m_AttackInterval += a_Dt * m_AttackRate;
if ((m_Target != NULL) && (m_AttackInterval > 3.0))
{
diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h
index 9cee4e7a7..152260f95 100644
--- a/src/Mobs/AggressiveMonster.h
+++ b/src/Mobs/AggressiveMonster.h
@@ -20,7 +20,7 @@ public:
virtual void InStateChasing(float a_Dt) override;
virtual void EventSeePlayer(cEntity *) override;
- virtual void Attack(float a_Dt) override;
+ virtual void Attack(float a_Dt);
} ;
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index ad3a87725..9817901c9 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -311,9 +311,6 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
}
}
- if (ReachedFinalDestination() && (m_Target != NULL))
- Attack(a_Dt);
-
SetPitchAndYawFromDestination();
HandleFalling();
@@ -657,17 +654,6 @@ void cMonster::InStateEscaping(float a_Dt)
-// Do attack here
-// a_Dt is passed so we can set attack rate
-void cMonster::Attack(float a_Dt)
-{
- m_AttackInterval += a_Dt * m_AttackRate;
-}
-
-
-
-
-
void cMonster::GetMonsterConfig(const AString & a_Name)
{
cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, a_Name);
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 714feddb9..4d2e099c5 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -112,8 +112,6 @@ public:
virtual void InStateChasing (float a_Dt);
virtual void InStateEscaping(float a_Dt);
- virtual void Attack(float a_Dt);
-
int GetAttackRate() { return (int)m_AttackRate; }
void SetAttackRate(float a_AttackRate) { m_AttackRate = a_AttackRate; }
void SetAttackRange(int a_AttackRange) { m_AttackRange = a_AttackRange; }