Large reworking of mob code [SEE DESC]

+ Implemented better pathfinding
- Removed lots of unused variables, functions, etc.
* Changed some variable types
* Other miscellaneous fixes, and also completes the previous PRs
This commit is contained in:
Tiger Wang
2014-01-24 19:57:32 +00:00
parent 161a1c7274
commit 9c0e3615ce
7 changed files with 336 additions and 244 deletions
+33 -34
View File
@@ -4,7 +4,6 @@
#include "AggressiveMonster.h"
#include "../World.h"
#include "../Vector3f.h"
#include "../Entities/Player.h"
#include "../MersenneTwister.h"
@@ -13,8 +12,7 @@
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),
m_ChaseTime(999999)
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
{
m_EMPersonality = AGGRESSIVE;
}
@@ -27,32 +25,23 @@ cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eType a_Mob
void cAggressiveMonster::InStateChasing(float a_Dt)
{
super::InStateChasing(a_Dt);
m_ChaseTime += a_Dt;
if (m_Target != NULL)
{
if (m_Target->IsPlayer())
{
cPlayer * Player = (cPlayer *) m_Target;
if (Player->IsGameModeCreative())
if (((cPlayer *)m_Target)->IsGameModeCreative())
{
m_EMState = IDLE;
return;
}
}
Vector3f Pos = Vector3f( GetPosition() );
Vector3f Their = Vector3f( m_Target->GetPosition() );
if ((Their - Pos).Length() <= m_AttackRange)
if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ()))
{
Attack(a_Dt);
MoveToPosition(m_Target->GetPosition());
}
MoveToPosition(Their + Vector3f(0, 0.65f, 0));
}
else if (m_ChaseTime > 5.f)
{
m_ChaseTime = 0;
m_EMState = IDLE;
}
}
@@ -62,7 +51,10 @@ void cAggressiveMonster::InStateChasing(float a_Dt)
void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
{
super::EventSeePlayer(a_Entity);
m_EMState = CHASING;
if (!((cPlayer *)a_Entity)->IsGameModeCreative())
{
m_EMState = CHASING;
}
}
@@ -73,25 +65,32 @@ void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
m_SeePlayerInterval += a_Dt;
if (m_SeePlayerInterval > 1)
if (m_EMState == CHASING)
{
int rem = m_World->GetTickRandomNumber(3) + 1; // Check most of the time but miss occasionally
m_SeePlayerInterval = 0.0;
if (rem >= 2)
{
if (m_EMState == CHASING)
{
CheckEventLostPlayer();
}
else
{
CheckEventSeePlayer();
}
}
CheckEventLostPlayer();
}
else
{
CheckEventSeePlayer();
}
}
void cAggressiveMonster::Attack(float a_Dt)
{
super::Attack(a_Dt);
if ((m_Target != NULL) && (m_AttackInterval > 3.0))
{
// Setting this higher gives us more wiggle room for attackrate
m_AttackInterval = 0.0;
m_Target->TakeDamage(dtMobAttack, this, m_AttackDamage, 0);
}
}