2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "AggressiveMonster.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-16 04:48:19 -04:00
|
|
|
#include "../World.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../Entities/Player.h"
|
2014-02-11 17:09:56 -05:00
|
|
|
#include "../Tracer.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-17 13:40:10 -04:00
|
|
|
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
|
2014-01-24 14:57:32 -05:00
|
|
|
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
m_EMPersonality = AGGRESSIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What to do if in Chasing State
|
2013-04-13 17:02:10 -04:00
|
|
|
void cAggressiveMonster::InStateChasing(float a_Dt)
|
2012-12-21 07:52:14 -05:00
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
super::InStateChasing(a_Dt);
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Target != nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-21 07:52:14 -05:00
|
|
|
if (m_Target->IsPlayer())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
if (((cPlayer *)m_Target)->IsGameModeCreative())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
m_EMState = IDLE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-25 15:59:55 -04:00
|
|
|
if (!IsMovingToTargetPosition())
|
2012-12-21 07:52:14 -05:00
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
MoveToPosition(m_Target->GetPosition());
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-12-21 07:52:14 -05:00
|
|
|
}
|
2014-07-17 16:50:58 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
if (!((cPlayer *)a_Entity)->IsGameModeCreative())
|
|
|
|
{
|
2014-01-25 14:00:50 -05:00
|
|
|
super::EventSeePlayer(a_Entity);
|
2014-01-24 14:57:32 -05:00
|
|
|
m_EMState = CHASING;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
super::Tick(a_Dt, a_Chunk);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
if (m_EMState == CHASING)
|
|
|
|
{
|
|
|
|
CheckEventLostPlayer();
|
|
|
|
}
|
|
|
|
else
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
CheckEventSeePlayer();
|
|
|
|
}
|
2014-02-11 17:09:56 -05:00
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Target == nullptr)
|
2014-02-12 16:53:21 -05:00
|
|
|
return;
|
|
|
|
|
2014-02-11 17:09:56 -05:00
|
|
|
cTracer LineOfSight(GetWorld());
|
2014-02-12 16:53:21 -05:00
|
|
|
Vector3d AttackDirection(m_Target->GetPosition() - GetPosition());
|
|
|
|
|
|
|
|
if (ReachedFinalDestination() && !LineOfSight.Trace(GetPosition(), AttackDirection, (int)AttackDirection.Length()))
|
2014-02-11 17:09:56 -05:00
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
}
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cAggressiveMonster::Attack(float a_Dt)
|
|
|
|
{
|
2014-02-11 17:09:56 -05:00
|
|
|
m_AttackInterval += a_Dt * m_AttackRate;
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((m_Target == nullptr) || (m_AttackInterval < 3.0))
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
2014-06-11 19:21:47 -04:00
|
|
|
return;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2014-06-11 19:21:47 -04:00
|
|
|
|
|
|
|
// Setting this higher gives us more wiggle room for attackrate
|
|
|
|
m_AttackInterval = 0.0;
|
|
|
|
m_Target->TakeDamage(dtMobAttack, this, m_AttackDamage, 0);
|
2012-12-21 07:52:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
|
2014-04-25 15:59:55 -04:00
|
|
|
bool cAggressiveMonster::IsMovingToTargetPosition()
|
|
|
|
{
|
2014-04-26 12:21:49 -04:00
|
|
|
// Difference between destination x and target x is negligible (to 10^-12 precision)
|
2014-04-27 12:35:41 -04:00
|
|
|
if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < std::numeric_limits<float>::epsilon())
|
2014-04-25 15:59:55 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-26 12:21:49 -04:00
|
|
|
// Difference between destination z and target z is negligible (to 10^-12 precision)
|
2014-04-27 12:35:41 -04:00
|
|
|
else if (fabsf((float)m_FinalDestination.z - (float)m_Target->GetPosZ()) > std::numeric_limits<float>::epsilon())
|
2014-04-25 15:59:55 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|