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:
parent
161a1c7274
commit
9c0e3615ce
@ -4,7 +4,6 @@
|
|||||||
#include "AggressiveMonster.h"
|
#include "AggressiveMonster.h"
|
||||||
|
|
||||||
#include "../World.h"
|
#include "../World.h"
|
||||||
#include "../Vector3f.h"
|
|
||||||
#include "../Entities/Player.h"
|
#include "../Entities/Player.h"
|
||||||
#include "../MersenneTwister.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) :
|
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),
|
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
|
||||||
m_ChaseTime(999999)
|
|
||||||
{
|
{
|
||||||
m_EMPersonality = AGGRESSIVE;
|
m_EMPersonality = AGGRESSIVE;
|
||||||
}
|
}
|
||||||
@ -27,31 +25,22 @@ cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eType a_Mob
|
|||||||
void cAggressiveMonster::InStateChasing(float a_Dt)
|
void cAggressiveMonster::InStateChasing(float a_Dt)
|
||||||
{
|
{
|
||||||
super::InStateChasing(a_Dt);
|
super::InStateChasing(a_Dt);
|
||||||
m_ChaseTime += a_Dt;
|
|
||||||
if (m_Target != NULL)
|
if (m_Target != NULL)
|
||||||
{
|
{
|
||||||
if (m_Target->IsPlayer())
|
if (m_Target->IsPlayer())
|
||||||
{
|
{
|
||||||
cPlayer * Player = (cPlayer *) m_Target;
|
if (((cPlayer *)m_Target)->IsGameModeCreative())
|
||||||
if (Player->IsGameModeCreative())
|
|
||||||
{
|
{
|
||||||
m_EMState = IDLE;
|
m_EMState = IDLE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f Pos = Vector3f( GetPosition() );
|
if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ()))
|
||||||
Vector3f Their = Vector3f( m_Target->GetPosition() );
|
|
||||||
if ((Their - Pos).Length() <= m_AttackRange)
|
|
||||||
{
|
{
|
||||||
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)
|
void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
|
||||||
{
|
{
|
||||||
super::EventSeePlayer(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);
|
super::Tick(a_Dt, a_Chunk);
|
||||||
|
|
||||||
m_SeePlayerInterval += a_Dt;
|
if (m_EMState == CHASING)
|
||||||
|
|
||||||
if (m_SeePlayerInterval > 1)
|
|
||||||
{
|
{
|
||||||
int rem = m_World->GetTickRandomNumber(3) + 1; // Check most of the time but miss occasionally
|
CheckEventLostPlayer();
|
||||||
|
}
|
||||||
m_SeePlayerInterval = 0.0;
|
else
|
||||||
if (rem >= 2)
|
{
|
||||||
{
|
CheckEventSeePlayer();
|
||||||
if (m_EMState == CHASING)
|
|
||||||
{
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,16 +13,15 @@ class cAggressiveMonster :
|
|||||||
typedef cMonster super;
|
typedef cMonster super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
|
cAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
|
||||||
|
|
||||||
virtual void Tick (float a_Dt, cChunk & a_Chunk) override;
|
virtual void Tick (float a_Dt, cChunk & a_Chunk) override;
|
||||||
virtual void InStateChasing(float a_Dt) override;
|
virtual void InStateChasing(float a_Dt) override;
|
||||||
|
|
||||||
virtual void EventSeePlayer(cEntity *) override;
|
virtual void EventSeePlayer(cEntity *) override;
|
||||||
|
virtual void Attack(float a_Dt) override;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
float m_ChaseTime;
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,13 +8,9 @@
|
|||||||
#include "../World.h"
|
#include "../World.h"
|
||||||
#include "../Entities/Player.h"
|
#include "../Entities/Player.h"
|
||||||
#include "../Entities/ExpOrb.h"
|
#include "../Entities/ExpOrb.h"
|
||||||
#include "../Defines.h"
|
|
||||||
#include "../MonsterConfig.h"
|
#include "../MonsterConfig.h"
|
||||||
#include "../MersenneTwister.h"
|
#include "../MersenneTwister.h"
|
||||||
|
|
||||||
#include "../Vector3f.h"
|
|
||||||
#include "../Vector3i.h"
|
|
||||||
#include "../Vector3d.h"
|
|
||||||
#include "../Tracer.h"
|
#include "../Tracer.h"
|
||||||
#include "../Chunk.h"
|
#include "../Chunk.h"
|
||||||
#include "../FastRandom.h"
|
#include "../FastRandom.h"
|
||||||
@ -81,11 +77,9 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString
|
|||||||
, m_bMovingToDestination(false)
|
, m_bMovingToDestination(false)
|
||||||
, m_DestinationTime( 0 )
|
, m_DestinationTime( 0 )
|
||||||
, m_DestroyTimer( 0 )
|
, m_DestroyTimer( 0 )
|
||||||
, m_Jump(0)
|
|
||||||
, m_MobType(a_MobType)
|
, m_MobType(a_MobType)
|
||||||
, m_SoundHurt(a_SoundHurt)
|
, m_SoundHurt(a_SoundHurt)
|
||||||
, m_SoundDeath(a_SoundDeath)
|
, m_SoundDeath(a_SoundDeath)
|
||||||
, m_SeePlayerInterval (0)
|
|
||||||
, m_AttackDamage(1.0f)
|
, m_AttackDamage(1.0f)
|
||||||
, m_AttackRange(2.0f)
|
, m_AttackRange(2.0f)
|
||||||
, m_AttackInterval(0)
|
, m_AttackInterval(0)
|
||||||
@ -110,11 +104,105 @@ void cMonster::SpawnOn(cClientHandle & a_Client)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cMonster::MoveToPosition( const Vector3f & a_Position )
|
void cMonster::TickPathFinding()
|
||||||
{
|
{
|
||||||
m_bMovingToDestination = true;
|
int PosX = (int)floor(GetPosX());
|
||||||
|
int PosY = (int)floor(GetPosY());
|
||||||
|
int PosZ = (int)floor(GetPosZ());
|
||||||
|
|
||||||
m_Destination = a_Position;
|
m_FinalDestination.y = (double)FindFirstNonAirBlockPosition(m_FinalDestination.x, m_FinalDestination.z);
|
||||||
|
|
||||||
|
std::vector<Vector3d> m_PotentialCoordinates;
|
||||||
|
m_TraversedCoordinates.push_back(Vector3i(PosX, PosY, PosZ));
|
||||||
|
|
||||||
|
static const struct // Define which directions the torch can power
|
||||||
|
{
|
||||||
|
int x, z;
|
||||||
|
} gCrossCoords[] =
|
||||||
|
{
|
||||||
|
{ 1, 0},
|
||||||
|
{-1, 0},
|
||||||
|
{ 0, 1},
|
||||||
|
{ 0,-1},
|
||||||
|
} ;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
|
||||||
|
{
|
||||||
|
if ((gCrossCoords[i].x + PosX == PosX) && (gCrossCoords[i].z + PosZ == PosZ))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsCoordinateInTraversedList(Vector3i(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BLOCKTYPE BlockAtY = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ);
|
||||||
|
BLOCKTYPE BlockAtYP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 1, gCrossCoords[i].z + PosZ);
|
||||||
|
BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ);
|
||||||
|
BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ);
|
||||||
|
|
||||||
|
if (!g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !IsBlockLava(BlockAtYM))
|
||||||
|
{
|
||||||
|
m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ));
|
||||||
|
}
|
||||||
|
else if (g_BlockIsSolid[BlockAtY] && !g_BlockIsSolid[BlockAtYP] && !g_BlockIsSolid[BlockAtYPP] && !IsBlockLava(BlockAtYM))
|
||||||
|
{
|
||||||
|
m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_PotentialCoordinates.empty())
|
||||||
|
{
|
||||||
|
Vector3f ShortestCoords = m_PotentialCoordinates.front();
|
||||||
|
for (std::vector<Vector3d>::const_iterator itr = m_PotentialCoordinates.begin(); itr != m_PotentialCoordinates.end(); ++itr)
|
||||||
|
{
|
||||||
|
Vector3f Distance = m_FinalDestination - ShortestCoords;
|
||||||
|
Vector3f Distance2 = m_FinalDestination - *itr;
|
||||||
|
if (Distance.SqrLength() > Distance2.SqrLength())
|
||||||
|
{
|
||||||
|
ShortestCoords = *itr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Destination = ShortestCoords;
|
||||||
|
m_Destination.z += 0.5f;
|
||||||
|
m_Destination.x += 0.5f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FinishPathFinding();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cMonster::MoveToPosition(const Vector3f & a_Position)
|
||||||
|
{
|
||||||
|
FinishPathFinding();
|
||||||
|
|
||||||
|
m_FinalDestination = a_Position;
|
||||||
|
m_bMovingToDestination = true;
|
||||||
|
TickPathFinding();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cMonster::IsCoordinateInTraversedList(Vector3i a_Coords)
|
||||||
|
{
|
||||||
|
for (std::vector<Vector3i>::const_iterator itr = m_TraversedCoordinates.begin(); itr != m_TraversedCoordinates.end(); ++itr)
|
||||||
|
{
|
||||||
|
if (itr->Equals(a_Coords))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -123,9 +211,23 @@ void cMonster::MoveToPosition( const Vector3f & a_Position )
|
|||||||
|
|
||||||
bool cMonster::ReachedDestination()
|
bool cMonster::ReachedDestination()
|
||||||
{
|
{
|
||||||
Vector3f Distance = (m_Destination) - GetPosition();
|
if ((m_Destination - GetPosition()).Length() < 0.5f)
|
||||||
if( Distance.SqrLength() < 2.f )
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cMonster::ReachedFinalDestination()
|
||||||
|
{
|
||||||
|
if ((GetPosition() - m_FinalDestination).Length() <= m_AttackRange)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -152,22 +254,18 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
// Burning in daylight
|
// Burning in daylight
|
||||||
HandleDaylightBurning(a_Chunk);
|
HandleDaylightBurning(a_Chunk);
|
||||||
|
|
||||||
HandlePhysics(a_Dt,a_Chunk);
|
|
||||||
BroadcastMovementUpdate();
|
|
||||||
|
|
||||||
a_Dt /= 1000;
|
a_Dt /= 1000;
|
||||||
|
|
||||||
if (m_bMovingToDestination)
|
if (m_bMovingToDestination)
|
||||||
{
|
{
|
||||||
Vector3f Pos( GetPosition() );
|
Vector3f Distance = m_Destination - GetPosition();
|
||||||
Vector3f Distance = m_Destination - Pos;
|
if(!ReachedDestination() && !ReachedFinalDestination()) // If we haven't reached any sort of destination, move
|
||||||
if( !ReachedDestination() )
|
|
||||||
{
|
{
|
||||||
Distance.y = 0;
|
Distance.y = 0;
|
||||||
Distance.Normalize();
|
Distance.Normalize();
|
||||||
Distance *= 3;
|
Distance *= 3;
|
||||||
SetSpeedX( Distance.x );
|
SetSpeedX(Distance.x);
|
||||||
SetSpeedZ( Distance.z );
|
SetSpeedZ(Distance.z);
|
||||||
|
|
||||||
if (m_EMState == ESCAPING)
|
if (m_EMState == ESCAPING)
|
||||||
{ //Runs Faster when escaping :D otherwise they just walk away
|
{ //Runs Faster when escaping :D otherwise they just walk away
|
||||||
@ -177,40 +275,32 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_bMovingToDestination = false;
|
if (ReachedFinalDestination()) // If we have reached the ultimate, final destination, stop pathfinding and attack if appropriate
|
||||||
|
{
|
||||||
|
FinishPathFinding();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TickPathFinding(); // We have reached the next point in our path, calculate another point
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( GetSpeed().SqrLength() > 0.f )
|
if(m_bOnGround)
|
||||||
{
|
{
|
||||||
if( m_bOnGround )
|
int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z);
|
||||||
|
|
||||||
|
if (IsNextYPosReachable(NextHeight))
|
||||||
{
|
{
|
||||||
Vector3f NormSpeed = Vector3f(GetSpeed()).NormalizeCopy();
|
m_bOnGround = false;
|
||||||
Vector3f NextBlock = Vector3f( GetPosition() ) + NormSpeed;
|
SetSpeedY(5.f); // Jump!!
|
||||||
int NextHeight;
|
|
||||||
if (!m_World->TryGetHeight((int)NextBlock.x, (int)NextBlock.z, NextHeight))
|
|
||||||
{
|
|
||||||
// The chunk at NextBlock is not loaded
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if( NextHeight > (GetPosY() - 1.0) && (NextHeight - GetPosY()) < 2.5 )
|
|
||||||
{
|
|
||||||
m_bOnGround = false;
|
|
||||||
SetSpeedY(5.f); // Jump!!
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3d Distance = m_Destination - GetPosition();
|
if (ReachedFinalDestination())
|
||||||
if (Distance.SqrLength() > 0.1f)
|
Attack(a_Dt);
|
||||||
{
|
|
||||||
double Rotation, Pitch;
|
SetPitchAndYawFromDestination();
|
||||||
Distance.Normalize();
|
|
||||||
VectorToEuler( Distance.x, Distance.y, Distance.z, Rotation, Pitch );
|
|
||||||
SetHeadYaw (Rotation);
|
|
||||||
SetYaw( Rotation );
|
|
||||||
SetPitch( -Pitch );
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (m_EMState)
|
switch (m_EMState)
|
||||||
{
|
{
|
||||||
@ -220,20 +310,86 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
InStateIdle(a_Dt);
|
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(a_Dt);
|
InStateChasing(a_Dt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ESCAPING:
|
case ESCAPING:
|
||||||
{
|
{
|
||||||
InStateEscaping(a_Dt);
|
InStateEscaping(a_Dt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} // switch (m_EMState)
|
} // switch (m_EMState)
|
||||||
|
|
||||||
|
BroadcastMovementUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cMonster::SetPitchAndYawFromDestination()
|
||||||
|
{
|
||||||
|
Vector3d FinalDestination = m_FinalDestination;
|
||||||
|
if (m_Target != NULL)
|
||||||
|
{
|
||||||
|
if (m_Target->IsPlayer())
|
||||||
|
{
|
||||||
|
FinalDestination.y = ((cPlayer *)m_Target)->GetStance();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FinalDestination.y = GetHeight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3d Distance = FinalDestination - GetPosition();
|
||||||
|
if (Distance.SqrLength() > 0.1f)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
double Rotation, Pitch;
|
||||||
|
Distance.Normalize();
|
||||||
|
VectorToEuler(Distance.x, Distance.y, Distance.z, Rotation, Pitch);
|
||||||
|
SetHeadYaw(Rotation);
|
||||||
|
SetPitch(-Pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Vector3d BodyDistance = m_Destination - GetPosition();
|
||||||
|
double Rotation, Pitch;
|
||||||
|
Distance.Normalize();
|
||||||
|
VectorToEuler(BodyDistance.x, BodyDistance.y, BodyDistance.z, Rotation, Pitch);
|
||||||
|
SetYaw(Rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
|
||||||
|
{
|
||||||
|
int PosY = (int)floor(GetPosY());
|
||||||
|
|
||||||
|
if (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))])
|
||||||
|
{
|
||||||
|
while (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY > 0))
|
||||||
|
{
|
||||||
|
PosY--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PosY + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY < cChunkDef::Height))
|
||||||
|
{
|
||||||
|
PosY++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PosY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -244,11 +400,13 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
|
void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
|
||||||
{
|
{
|
||||||
super::DoTakeDamage(a_TDI);
|
super::DoTakeDamage(a_TDI);
|
||||||
if((m_SoundHurt != "") && (m_Health > 0)) m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
|
|
||||||
|
if((m_SoundHurt != "") && (m_Health > 0))
|
||||||
|
m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
|
||||||
|
|
||||||
if (a_TDI.Attacker != NULL)
|
if (a_TDI.Attacker != NULL)
|
||||||
{
|
{
|
||||||
m_Target = a_TDI.Attacker;
|
m_Target = a_TDI.Attacker;
|
||||||
AddReference(m_Target);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,55 +488,12 @@ void cMonster::KilledBy(cEntity * a_Killer)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----State Logic
|
|
||||||
|
|
||||||
const char *cMonster::GetState()
|
|
||||||
{
|
|
||||||
switch(m_EMState)
|
|
||||||
{
|
|
||||||
case IDLE: return "Idle";
|
|
||||||
case ATTACKING: return "Attacking";
|
|
||||||
case CHASING: return "Chasing";
|
|
||||||
default: return "Unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// for debugging
|
|
||||||
void cMonster::SetState(const AString & a_State)
|
|
||||||
{
|
|
||||||
if (a_State.compare("Idle") == 0)
|
|
||||||
{
|
|
||||||
m_EMState = IDLE;
|
|
||||||
}
|
|
||||||
else if (a_State.compare("Attacking") == 0)
|
|
||||||
{
|
|
||||||
m_EMState = ATTACKING;
|
|
||||||
}
|
|
||||||
else if (a_State.compare("Chasing") == 0)
|
|
||||||
{
|
|
||||||
m_EMState = CHASING;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOGD("cMonster::SetState(): Invalid state");
|
|
||||||
ASSERT(!"Invalid state");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Checks to see if EventSeePlayer should be fired
|
//Checks to see if EventSeePlayer should be fired
|
||||||
//monster sez: Do I see the player
|
//monster sez: Do I see the player
|
||||||
void cMonster::CheckEventSeePlayer(void)
|
void cMonster::CheckEventSeePlayer(void)
|
||||||
{
|
{
|
||||||
// TODO: Rewrite this to use cWorld's DoWithPlayers()
|
// TODO: Rewrite this to use cWorld's DoWithPlayers()
|
||||||
cPlayer * Closest = FindClosestPlayer();
|
cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), m_SightDistance);
|
||||||
|
|
||||||
if (Closest != NULL)
|
if (Closest != NULL)
|
||||||
{
|
{
|
||||||
@ -398,7 +513,10 @@ void cMonster::CheckEventLostPlayer(void)
|
|||||||
if (m_Target != NULL)
|
if (m_Target != NULL)
|
||||||
{
|
{
|
||||||
pos = m_Target->GetPosition();
|
pos = m_Target->GetPosition();
|
||||||
if ((pos - GetPosition()).Length() > m_SightDistance || LineOfSight.Trace(GetPosition(),(pos - GetPosition()), (int)(pos - GetPosition()).Length()))
|
if (
|
||||||
|
((pos - GetPosition()).Length() > m_SightDistance) ||
|
||||||
|
LineOfSight.Trace(Vector3d(GetPosX(), GetPosY() + 1, GetPosZ()), (pos - GetPosition()), (int)(pos - GetPosition()).Length())
|
||||||
|
)
|
||||||
{
|
{
|
||||||
EventLosePlayer();
|
EventLosePlayer();
|
||||||
}
|
}
|
||||||
@ -418,7 +536,6 @@ void cMonster::CheckEventLostPlayer(void)
|
|||||||
void cMonster::EventSeePlayer(cEntity * a_SeenPlayer)
|
void cMonster::EventSeePlayer(cEntity * a_SeenPlayer)
|
||||||
{
|
{
|
||||||
m_Target = a_SeenPlayer;
|
m_Target = a_SeenPlayer;
|
||||||
AddReference(m_Target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -427,7 +544,6 @@ void cMonster::EventSeePlayer(cEntity * a_SeenPlayer)
|
|||||||
|
|
||||||
void cMonster::EventLosePlayer(void)
|
void cMonster::EventLosePlayer(void)
|
||||||
{
|
{
|
||||||
Dereference(m_Target);
|
|
||||||
m_Target = NULL;
|
m_Target = NULL;
|
||||||
m_EMState = IDLE;
|
m_EMState = IDLE;
|
||||||
}
|
}
|
||||||
@ -436,27 +552,30 @@ void cMonster::EventLosePlayer(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// What to do if in Idle State
|
|
||||||
void cMonster::InStateIdle(float a_Dt)
|
void cMonster::InStateIdle(float a_Dt)
|
||||||
{
|
{
|
||||||
m_IdleInterval += a_Dt;
|
m_IdleInterval += a_Dt;
|
||||||
|
|
||||||
if (m_IdleInterval > 1)
|
if (m_IdleInterval > 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;
|
||||||
// LOGD("Moving: int: %3.3f rem: %i",idle_interval,rem);
|
m_IdleInterval -= 1; // So nothing gets dropped when the server hangs for a few seconds
|
||||||
m_IdleInterval -= 1; // So nothing gets dropped when the server hangs for a few seconds
|
|
||||||
Vector3f Dist;
|
Vector3d Dist;
|
||||||
Dist.x = (float)(m_World->GetTickRandomNumber(10) - 5);
|
Dist.x = (double)m_World->GetTickRandomNumber(m_SightDistance * 2) - m_SightDistance;
|
||||||
Dist.z = (float)(m_World->GetTickRandomNumber(10) - 5);
|
Dist.z = (double)m_World->GetTickRandomNumber(m_SightDistance * 2) - m_SightDistance;
|
||||||
|
|
||||||
if ((Dist.SqrLength() > 2) && (rem >= 3))
|
if ((Dist.SqrLength() > 2) && (rem >= 3))
|
||||||
{
|
{
|
||||||
m_Destination.x = (float)(GetPosX() + Dist.x);
|
m_Destination.x = GetPosX() + Dist.x;
|
||||||
m_Destination.z = (float)(GetPosZ() + Dist.z);
|
m_Destination.z = GetPosZ() + Dist.z;
|
||||||
int PosY;
|
|
||||||
if (m_World->TryGetHeight((int)m_Destination.x, (int)m_Destination.z, PosY))
|
int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z);
|
||||||
|
|
||||||
|
if (IsNextYPosReachable(NextHeight + 1))
|
||||||
{
|
{
|
||||||
m_Destination.y = (float)PosY + 1.2f;
|
m_Destination.y = (double)NextHeight;
|
||||||
MoveToPosition(m_Destination);
|
MoveToPosition(m_Destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -505,22 +624,6 @@ void cMonster::InStateEscaping(float a_Dt)
|
|||||||
void cMonster::Attack(float a_Dt)
|
void cMonster::Attack(float a_Dt)
|
||||||
{
|
{
|
||||||
m_AttackInterval += a_Dt * m_AttackRate;
|
m_AttackInterval += a_Dt * m_AttackRate;
|
||||||
if ((m_Target != NULL) && (m_AttackInterval > 3.0))
|
|
||||||
{
|
|
||||||
// Setting this higher gives us more wiggle room for attackrate
|
|
||||||
m_AttackInterval = 0.0;
|
|
||||||
((cPawn *)m_Target)->TakeDamage(*this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Checks for Players close by and if they are visible return the closest
|
|
||||||
cPlayer * cMonster::FindClosestPlayer(void)
|
|
||||||
{
|
|
||||||
return m_World->FindClosestPlayer(GetPosition(), m_SightDistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -536,42 +639,6 @@ void cMonster::GetMonsterConfig(const AString & a_Name)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cMonster::SetAttackRate(int ar)
|
|
||||||
{
|
|
||||||
m_AttackRate = (float)ar;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cMonster::SetAttackRange(float ar)
|
|
||||||
{
|
|
||||||
m_AttackRange = ar;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cMonster::SetAttackDamage(float ad)
|
|
||||||
{
|
|
||||||
m_AttackDamage = ad;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cMonster::SetSightDistance(float sd)
|
|
||||||
{
|
|
||||||
m_SightDistance = sd;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AString cMonster::MobTypeToString(cMonster::eType a_MobType)
|
AString cMonster::MobTypeToString(cMonster::eType a_MobType)
|
||||||
{
|
{
|
||||||
// Mob types aren't sorted, so we need to search linearly:
|
// Mob types aren't sorted, so we need to search linearly:
|
||||||
@ -635,6 +702,8 @@ cMonster::eType cMonster::StringToMobType(const AString & a_Name)
|
|||||||
|
|
||||||
cMonster::eFamily cMonster::FamilyFromType(eType a_Type)
|
cMonster::eFamily cMonster::FamilyFromType(eType a_Type)
|
||||||
{
|
{
|
||||||
|
// Passive-agressive mobs are counted in mob spawning code as passive
|
||||||
|
|
||||||
switch (a_Type)
|
switch (a_Type)
|
||||||
{
|
{
|
||||||
case mtBat: return mfAmbient;
|
case mtBat: return mfAmbient;
|
||||||
@ -699,7 +768,7 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType)
|
|||||||
case mtMagmaCube:
|
case mtMagmaCube:
|
||||||
case mtSlime:
|
case mtSlime:
|
||||||
{
|
{
|
||||||
toReturn = new cSlime (Random.NextInt(2) + 1);
|
toReturn = new cSlime(Random.NextInt(2) + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case mtSkeleton:
|
case mtSkeleton:
|
||||||
@ -803,6 +872,13 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk)
|
|||||||
|
|
||||||
int RelX = (int)floor(GetPosX()) - GetChunkX() * cChunkDef::Width;
|
int RelX = (int)floor(GetPosX()) - GetChunkX() * cChunkDef::Width;
|
||||||
int RelZ = (int)floor(GetPosZ()) - GetChunkZ() * cChunkDef::Width;
|
int RelZ = (int)floor(GetPosZ()) - GetChunkZ() * cChunkDef::Width;
|
||||||
|
|
||||||
|
if (!a_Chunk.IsLightValid())
|
||||||
|
{
|
||||||
|
m_World->QueueLightChunk(GetChunkX(), GetChunkZ());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(a_Chunk.GetSkyLight(RelX, RelY, RelZ) == 15) && // In the daylight
|
(a_Chunk.GetSkyLight(RelX, RelY, RelZ) == 15) && // In the daylight
|
||||||
(a_Chunk.GetBlock(RelX, RelY, RelZ) != E_BLOCK_SOULSAND) && // Not on soulsand
|
(a_Chunk.GetBlock(RelX, RelY, RelZ) != E_BLOCK_SOULSAND) && // Not on soulsand
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Vector3f;
|
|
||||||
class cClientHandle;
|
class cClientHandle;
|
||||||
class cWorld;
|
class cWorld;
|
||||||
|
|
||||||
@ -74,8 +73,6 @@ public:
|
|||||||
enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState;
|
enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState;
|
||||||
enum MPersonality{PASSIVE,AGGRESSIVE,COWARDLY} m_EMPersonality;
|
enum MPersonality{PASSIVE,AGGRESSIVE,COWARDLY} m_EMPersonality;
|
||||||
|
|
||||||
float m_SightDistance;
|
|
||||||
|
|
||||||
/** Creates the mob object.
|
/** Creates the mob object.
|
||||||
* If a_ConfigName is not empty, the configuration is loaded using GetMonsterConfig()
|
* If a_ConfigName is not empty, the configuration is loaded using GetMonsterConfig()
|
||||||
* a_MobType is the type of the mob (also used in the protocol ( http://wiki.vg/Entities#Mobs , 2012_12_22))
|
* a_MobType is the type of the mob (also used in the protocol ( http://wiki.vg/Entities#Mobs , 2012_12_22))
|
||||||
@ -101,13 +98,8 @@ public:
|
|||||||
eFamily GetMobFamily(void) const;
|
eFamily GetMobFamily(void) const;
|
||||||
// tolua_end
|
// tolua_end
|
||||||
|
|
||||||
|
|
||||||
const char * GetState();
|
|
||||||
void SetState(const AString & str);
|
|
||||||
|
|
||||||
virtual void CheckEventSeePlayer(void);
|
virtual void CheckEventSeePlayer(void);
|
||||||
virtual void EventSeePlayer(cEntity * a_Player);
|
virtual void EventSeePlayer(cEntity * a_Player);
|
||||||
virtual cPlayer * FindClosestPlayer(); // non static is easier. also virtual so other mobs can implement their own searching algo
|
|
||||||
|
|
||||||
/// Reads the monster configuration for the specified monster name and assigns it to this object.
|
/// Reads the monster configuration for the specified monster name and assigns it to this object.
|
||||||
void GetMonsterConfig(const AString & a_Name);
|
void GetMonsterConfig(const AString & a_Name);
|
||||||
@ -121,11 +113,11 @@ public:
|
|||||||
|
|
||||||
virtual void Attack(float a_Dt);
|
virtual void Attack(float a_Dt);
|
||||||
|
|
||||||
int GetAttackRate(){return (int)m_AttackRate;}
|
int GetAttackRate() { return (int)m_AttackRate; }
|
||||||
void SetAttackRate(int ar);
|
void SetAttackRate(float a_AttackRate) { m_AttackRate = a_AttackRate; }
|
||||||
void SetAttackRange(float ar);
|
void SetAttackRange(int a_AttackRange) { m_AttackRange = a_AttackRange; }
|
||||||
void SetAttackDamage(float ad);
|
void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; }
|
||||||
void SetSightDistance(float sd);
|
void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; }
|
||||||
|
|
||||||
/// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick
|
/// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick
|
||||||
void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; }
|
void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; }
|
||||||
@ -159,34 +151,72 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
/* ======= PATHFINDING ======= */
|
||||||
|
|
||||||
|
/** A pointer to the entity this mobile is aiming to reach */
|
||||||
cEntity * m_Target;
|
cEntity * m_Target;
|
||||||
|
/** Coordinates of the next position that should be reached */
|
||||||
|
Vector3d m_Destination;
|
||||||
|
/** Coordinates for the ultimate, final destination. */
|
||||||
|
Vector3d m_FinalDestination;
|
||||||
|
/** Returns if the ultimate, final destination has been reached */
|
||||||
|
bool ReachedFinalDestination(void);
|
||||||
|
|
||||||
|
/** Stores if mobile is currently moving towards the ultimate, final destination */
|
||||||
|
bool m_bMovingToDestination;
|
||||||
|
/** Finds the first non-air block position (not the highest, as cWorld::GetHeight does)
|
||||||
|
If current Y is nonsolid, goes down to try to find a solid block, then returns that + 1
|
||||||
|
If current Y is solid, goes up to find first nonsolid block, and returns that */
|
||||||
|
int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ);
|
||||||
|
|
||||||
|
/** A semi-temporary list to store the traversed coordinates during active pathfinding so we don't visit them again */
|
||||||
|
std::vector<Vector3i> m_TraversedCoordinates;
|
||||||
|
/** Returns if coordinate is in the traversed list */
|
||||||
|
bool IsCoordinateInTraversedList(Vector3i a_Coords);
|
||||||
|
|
||||||
|
/** Finds the next place to go
|
||||||
|
This is based on the ultimate, final destination and the current position, as well as the traversed coordinates, and any environmental hazards */
|
||||||
|
void TickPathFinding(void);
|
||||||
|
/** Finishes a pathfinding task, be it due to failure or something else */
|
||||||
|
inline void FinishPathFinding(void)
|
||||||
|
{
|
||||||
|
m_TraversedCoordinates.clear();
|
||||||
|
m_bMovingToDestination = false;
|
||||||
|
}
|
||||||
|
/** Sets the body yaw and head yaw/pitch based on next/ultimate destinations */
|
||||||
|
void SetPitchAndYawFromDestination(void);
|
||||||
|
|
||||||
|
/* ===========================*/
|
||||||
|
|
||||||
float m_AttackRate;
|
float m_AttackRate;
|
||||||
float m_IdleInterval;
|
float m_IdleInterval;
|
||||||
|
|
||||||
Vector3f m_Destination;
|
|
||||||
bool m_bMovingToDestination;
|
|
||||||
bool m_bPassiveAggressive;
|
bool m_bPassiveAggressive;
|
||||||
|
|
||||||
float m_DestinationTime;
|
float m_DestinationTime;
|
||||||
|
|
||||||
float m_DestroyTimer;
|
float m_DestroyTimer;
|
||||||
float m_Jump;
|
|
||||||
|
|
||||||
eType m_MobType;
|
eType m_MobType;
|
||||||
|
|
||||||
AString m_SoundHurt;
|
AString m_SoundHurt;
|
||||||
AString m_SoundDeath;
|
AString m_SoundDeath;
|
||||||
|
|
||||||
float m_SeePlayerInterval;
|
int m_AttackDamage;
|
||||||
float m_AttackDamage;
|
int m_AttackRange;
|
||||||
float m_AttackRange;
|
|
||||||
float m_AttackInterval;
|
float m_AttackInterval;
|
||||||
|
int m_SightDistance;
|
||||||
|
|
||||||
bool m_BurnsInDaylight;
|
bool m_BurnsInDaylight;
|
||||||
|
|
||||||
void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0);
|
void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0);
|
||||||
|
|
||||||
void HandleDaylightBurning(cChunk & a_Chunk);
|
void HandleDaylightBurning(cChunk & a_Chunk);
|
||||||
|
inline bool IsNextYPosReachable(int a_PosY)
|
||||||
|
{
|
||||||
|
return (a_PosY > (int)floor(GetPosY())) && (a_PosY == (int)floor(GetPosY()) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
} ; // tolua_export
|
} ; // tolua_export
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||||
|
|
||||||
#include "PassiveMonster.h"
|
#include "PassiveMonster.h"
|
||||||
#include "../MersenneTwister.h"
|
|
||||||
#include "../World.h"
|
#include "../World.h"
|
||||||
|
|
||||||
|
|
||||||
@ -36,20 +35,9 @@ void cPassiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
{
|
{
|
||||||
super::Tick(a_Dt, a_Chunk);
|
super::Tick(a_Dt, a_Chunk);
|
||||||
|
|
||||||
m_SeePlayerInterval += a_Dt;
|
if (m_EMState == ESCAPING)
|
||||||
|
|
||||||
if (m_SeePlayerInterval > 1) // Check every second
|
|
||||||
{
|
{
|
||||||
int rem = m_World->GetTickRandomNumber(3) + 1; // Check most of the time but miss occasionally
|
CheckEventLostPlayer();
|
||||||
|
|
||||||
m_SeePlayerInterval = 0.0;
|
|
||||||
if (rem >= 2)
|
|
||||||
{
|
|
||||||
if (m_EMState == ESCAPING)
|
|
||||||
{
|
|
||||||
CheckEventLostPlayer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
m_bMovingToDestination = false;
|
m_bMovingToDestination = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cPlayer * a_Closest_Player = FindClosestPlayer();
|
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), m_SightDistance);
|
||||||
if (a_Closest_Player != NULL)
|
if (a_Closest_Player != NULL)
|
||||||
{
|
{
|
||||||
switch (a_Closest_Player->GetEquippedItem().m_ItemType)
|
switch (a_Closest_Player->GetEquippedItem().m_ItemType)
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
struct cMonsterConfig::sAttributesStruct
|
struct cMonsterConfig::sAttributesStruct
|
||||||
{
|
{
|
||||||
AString m_Name;
|
AString m_Name;
|
||||||
double m_SightDistance;
|
int m_SightDistance;
|
||||||
double m_AttackDamage;
|
int m_AttackDamage;
|
||||||
double m_AttackRange;
|
int m_AttackRange;
|
||||||
double m_AttackRate;
|
double m_AttackRate;
|
||||||
int m_MaxHealth;
|
int m_MaxHealth;
|
||||||
};
|
};
|
||||||
@ -67,9 +67,9 @@ void cMonsterConfig::Initialize()
|
|||||||
sAttributesStruct Attributes;
|
sAttributesStruct Attributes;
|
||||||
AString Name = MonstersIniFile.GetKeyName(i);
|
AString Name = MonstersIniFile.GetKeyName(i);
|
||||||
Attributes.m_Name = Name;
|
Attributes.m_Name = Name;
|
||||||
Attributes.m_AttackDamage = MonstersIniFile.GetValueF(Name, "AttackDamage", 0);
|
Attributes.m_AttackDamage = MonstersIniFile.GetValueI(Name, "AttackDamage", 0);
|
||||||
Attributes.m_AttackRange = MonstersIniFile.GetValueF(Name, "AttackRange", 0);
|
Attributes.m_AttackRange = MonstersIniFile.GetValueI(Name, "AttackRange", 0);
|
||||||
Attributes.m_SightDistance = MonstersIniFile.GetValueF(Name, "SightDistance", 0);
|
Attributes.m_SightDistance = MonstersIniFile.GetValueI(Name, "SightDistance", 0);
|
||||||
Attributes.m_AttackRate = MonstersIniFile.GetValueF(Name, "AttackRate", 0);
|
Attributes.m_AttackRate = MonstersIniFile.GetValueF(Name, "AttackRate", 0);
|
||||||
Attributes.m_MaxHealth = MonstersIniFile.GetValueI(Name, "MaxHealth", 1);
|
Attributes.m_MaxHealth = MonstersIniFile.GetValueI(Name, "MaxHealth", 1);
|
||||||
m_pState->AttributesList.push_front(Attributes);
|
m_pState->AttributesList.push_front(Attributes);
|
||||||
@ -87,10 +87,10 @@ void cMonsterConfig::AssignAttributes(cMonster * a_Monster, const AString & a_Na
|
|||||||
{
|
{
|
||||||
if (itr->m_Name.compare(a_Name) == 0)
|
if (itr->m_Name.compare(a_Name) == 0)
|
||||||
{
|
{
|
||||||
a_Monster->SetAttackDamage ((float)itr->m_AttackDamage);
|
a_Monster->SetAttackDamage (itr->m_AttackDamage);
|
||||||
a_Monster->SetAttackRange ((float)itr->m_AttackRange);
|
a_Monster->SetAttackRange (itr->m_AttackRange);
|
||||||
a_Monster->SetSightDistance((float)itr->m_SightDistance);
|
a_Monster->SetSightDistance(itr->m_SightDistance);
|
||||||
a_Monster->SetAttackRate ((int)itr->m_AttackRate);
|
a_Monster->SetAttackRate ((float)itr->m_AttackRate);
|
||||||
a_Monster->SetMaxHealth (itr->m_MaxHealth);
|
a_Monster->SetMaxHealth (itr->m_MaxHealth);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user