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
|
|
|
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "../Vector3f.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../Player.h"
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "../MersenneTwister.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 04:39:13 -05:00
|
|
|
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath) :
|
|
|
|
super(a_ConfigName, a_ProtocolMobType, a_SoundHurt, a_SoundDeath),
|
|
|
|
m_ChaseTime(999999)
|
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);
|
2012-06-14 09:06:06 -04:00
|
|
|
m_ChaseTime += a_Dt;
|
2012-12-21 07:52:14 -05:00
|
|
|
if (m_Target != NULL)
|
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
|
|
|
{
|
|
|
|
cPlayer * Player = (cPlayer *) m_Target;
|
2012-12-21 07:52:14 -05:00
|
|
|
if (Player->GetGameMode() == 1)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
m_EMState = IDLE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 02:33:10 -04:00
|
|
|
Vector3f Pos = Vector3f( GetPosition() );
|
2012-06-14 09:06:06 -04:00
|
|
|
Vector3f Their = Vector3f( m_Target->GetPosition() );
|
2012-12-21 07:52:14 -05:00
|
|
|
if ((Their - Pos).Length() <= m_AttackRange)
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
cMonster::Attack(a_Dt);
|
|
|
|
}
|
2012-12-21 07:52:14 -05:00
|
|
|
MoveToPosition(Their + Vector3f(0, 0.65f, 0));
|
|
|
|
}
|
|
|
|
else if (m_ChaseTime > 5.f)
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
m_ChaseTime = 0;
|
|
|
|
m_EMState = IDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
super::EventSeePlayer(a_Entity);
|
2012-06-14 09:06:06 -04:00
|
|
|
m_EMState = CHASING;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
m_SeePlayerInterval += a_Dt;
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
if (m_SeePlayerInterval > 1)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
int rem = m_World->GetTickRandomNumber(3) + 1; // Check most of the time but miss occasionally
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
m_SeePlayerInterval = 0.0;
|
2012-12-21 07:52:14 -05:00
|
|
|
if (rem >= 2)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-21 07:52:14 -05:00
|
|
|
if (m_EMState == CHASING)
|
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
CheckEventLostPlayer();
|
2012-12-21 07:52:14 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
CheckEventSeePlayer();
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-21 07:52:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|