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