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"
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "../Vector3f.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../Entities/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
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-20 04:23:30 -04:00
|
|
|
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
|
|
|
|
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height),
|
2012-12-22 04:39:13 -05:00
|
|
|
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;
|
2013-10-29 16:45:31 -04:00
|
|
|
if (Player->IsGameModeCreative())
|
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)
|
|
|
|
{
|
2013-11-04 15:46:56 -05:00
|
|
|
Attack(a_Dt);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|