Converted Monster to std::chrono
This commit is contained in:
parent
05c40db060
commit
bfe1960191
|
@ -22,7 +22,7 @@ cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eMonsterTyp
|
||||||
|
|
||||||
|
|
||||||
// What to do if in Chasing State
|
// What to do if in Chasing State
|
||||||
void cAggressiveMonster::InStateChasing(float a_Dt)
|
void cAggressiveMonster::InStateChasing(std::chrono::milliseconds a_Dt)
|
||||||
{
|
{
|
||||||
super::InStateChasing(a_Dt);
|
super::InStateChasing(a_Dt);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
|
cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
|
||||||
|
|
||||||
virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
|
virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
|
||||||
virtual void InStateChasing(float a_Dt) override;
|
virtual void InStateChasing(std::chrono::milliseconds a_Dt) override;
|
||||||
|
|
||||||
virtual void EventSeePlayer(cEntity *) override;
|
virtual void EventSeePlayer(cEntity *) override;
|
||||||
virtual void Attack(std::chrono::milliseconds a_Dt);
|
virtual void Attack(std::chrono::milliseconds a_Dt);
|
||||||
|
|
|
@ -259,8 +259,8 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
||||||
if (m_Health <= 0)
|
if (m_Health <= 0)
|
||||||
{
|
{
|
||||||
// The mob is dead, but we're still animating the "puff" they leave when they die
|
// The mob is dead, but we're still animating the "puff" they leave when they die
|
||||||
m_DestroyTimer += a_Dt.count() / 1000;
|
m_DestroyTimer += a_Dt;
|
||||||
if (m_DestroyTimer > 1)
|
if (m_DestroyTimer > std::chrono::seconds(1))
|
||||||
{
|
{
|
||||||
Destroy(true);
|
Destroy(true);
|
||||||
}
|
}
|
||||||
|
@ -345,18 +345,18 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
||||||
case IDLE:
|
case IDLE:
|
||||||
{
|
{
|
||||||
// If enemy passive we ignore checks for player visibility
|
// If enemy passive we ignore checks for player visibility
|
||||||
InStateIdle(std::chrono::duration_cast<std::chrono::seconds>(a_Dt).count());
|
InStateIdle(a_Dt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CHASING:
|
case CHASING:
|
||||||
{
|
{
|
||||||
// If we do not see a player anymore skip chasing action
|
// If we do not see a player anymore skip chasing action
|
||||||
InStateChasing(std::chrono::duration_cast<std::chrono::seconds>(a_Dt).count());
|
InStateChasing(a_Dt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESCAPING:
|
case ESCAPING:
|
||||||
{
|
{
|
||||||
InStateEscaping(std::chrono::duration_cast<std::chrono::seconds>(a_Dt).count());
|
InStateEscaping(a_Dt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ void cMonster::KilledBy(TakeDamageInfo & a_TDI)
|
||||||
{
|
{
|
||||||
m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward);
|
m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward);
|
||||||
}
|
}
|
||||||
m_DestroyTimer = 0;
|
m_DestroyTimer = std::chrono::milliseconds(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -638,7 +638,7 @@ void cMonster::EventLosePlayer(void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cMonster::InStateIdle(float a_Dt)
|
void cMonster::InStateIdle(std::chrono::milliseconds a_Dt)
|
||||||
{
|
{
|
||||||
if (m_bMovingToDestination)
|
if (m_bMovingToDestination)
|
||||||
{
|
{
|
||||||
|
@ -647,11 +647,11 @@ void cMonster::InStateIdle(float a_Dt)
|
||||||
|
|
||||||
m_IdleInterval += a_Dt;
|
m_IdleInterval += a_Dt;
|
||||||
|
|
||||||
if (m_IdleInterval > 1)
|
if (m_IdleInterval > std::chrono::seconds(1))
|
||||||
{
|
{
|
||||||
// At this interval the results are predictable
|
// At this interval the results are predictable
|
||||||
int rem = m_World->GetTickRandomNumber(6) + 1;
|
int rem = m_World->GetTickRandomNumber(6) + 1;
|
||||||
m_IdleInterval -= 1; // So nothing gets dropped when the server hangs for a few seconds
|
m_IdleInterval -= std::chrono::seconds(1); // So nothing gets dropped when the server hangs for a few seconds
|
||||||
|
|
||||||
Vector3d Dist;
|
Vector3d Dist;
|
||||||
Dist.x = (double)m_World->GetTickRandomNumber(10) - 5;
|
Dist.x = (double)m_World->GetTickRandomNumber(10) - 5;
|
||||||
|
@ -678,7 +678,7 @@ void cMonster::InStateIdle(float a_Dt)
|
||||||
|
|
||||||
// What to do if in Chasing State
|
// What to do if in Chasing State
|
||||||
// This state should always be defined in each child class
|
// This state should always be defined in each child class
|
||||||
void cMonster::InStateChasing(float a_Dt)
|
void cMonster::InStateChasing(std::chrono::milliseconds a_Dt)
|
||||||
{
|
{
|
||||||
UNUSED(a_Dt);
|
UNUSED(a_Dt);
|
||||||
}
|
}
|
||||||
|
@ -688,7 +688,7 @@ void cMonster::InStateChasing(float a_Dt)
|
||||||
|
|
||||||
|
|
||||||
// What to do if in Escaping State
|
// What to do if in Escaping State
|
||||||
void cMonster::InStateEscaping(float a_Dt)
|
void cMonster::InStateEscaping(std::chrono::milliseconds a_Dt)
|
||||||
{
|
{
|
||||||
UNUSED(a_Dt);
|
UNUSED(a_Dt);
|
||||||
|
|
||||||
|
|
|
@ -80,9 +80,9 @@ public:
|
||||||
virtual void EventLosePlayer(void);
|
virtual void EventLosePlayer(void);
|
||||||
virtual void CheckEventLostPlayer(void);
|
virtual void CheckEventLostPlayer(void);
|
||||||
|
|
||||||
virtual void InStateIdle (float a_Dt);
|
virtual void InStateIdle (std::chrono::milliseconds a_Dt);
|
||||||
virtual void InStateChasing (float a_Dt);
|
virtual void InStateChasing (std::chrono::milliseconds a_Dt);
|
||||||
virtual void InStateEscaping(float a_Dt);
|
virtual void InStateEscaping(std::chrono::milliseconds a_Dt);
|
||||||
|
|
||||||
int GetAttackRate() { return static_cast<int>(m_AttackRate); }
|
int GetAttackRate() { return static_cast<int>(m_AttackRate); }
|
||||||
void SetAttackRate(float a_AttackRate) { m_AttackRate = a_AttackRate; }
|
void SetAttackRate(float a_AttackRate) { m_AttackRate = a_AttackRate; }
|
||||||
|
@ -217,8 +217,8 @@ protected:
|
||||||
|
|
||||||
/* =========================== */
|
/* =========================== */
|
||||||
|
|
||||||
float m_IdleInterval;
|
std::chrono::milliseconds m_IdleInterval;
|
||||||
float m_DestroyTimer;
|
std::chrono::milliseconds m_DestroyTimer;
|
||||||
|
|
||||||
eMonsterType m_MobType;
|
eMonsterType m_MobType;
|
||||||
AString m_CustomName;
|
AString m_CustomName;
|
||||||
|
|
Loading…
Reference in New Issue