1
0

Merge pull request #2363 from scribblemaniac/improve-spider-ai

Improved spider AI
This commit is contained in:
Tiger Wang 2015-07-16 22:22:48 +01:00
commit c633dd8cec
3 changed files with 44 additions and 1 deletions

View File

@ -3,7 +3,8 @@
#include "Spider.h"
#include "../World.h"
#include "../Entities/Player.h"
@ -33,3 +34,42 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cSpider::EventSeePlayer(cEntity * a_Entity)
{
if (!GetWorld()->IsChunkLighted(GetChunkX(), GetChunkZ()))
{
GetWorld()->QueueLightChunk(GetChunkX(), GetChunkZ());
return;
}
if (!static_cast<cPlayer *>(a_Entity)->IsGameModeCreative() && (GetWorld()->GetBlockBlockLight(this->GetPosition()) <= 9))
{
super::EventSeePlayer(a_Entity);
}
}
bool cSpider::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if (!super::DoTakeDamage(a_TDI))
{
return false;
}
// If the source of the damage is not from an pawn entity, switch to idle
if ((a_TDI.Attacker == nullptr) || !a_TDI.Attacker->IsPawn())
{
m_EMState = IDLE;
}
else
{
// If the source of the damage is from a pawn entity, chase that entity
m_EMState = CHASING;
}
return true;
}

View File

@ -18,6 +18,8 @@ public:
CLASS_PROTODEF(cSpider)
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual void EventSeePlayer(cEntity *) override;
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
} ;

View File

@ -484,6 +484,7 @@ public:
BLOCKTYPE GetBlock (const Vector3i & a_Pos) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z); }
NIBBLETYPE GetBlockMeta(const Vector3i & a_Pos) { return GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z); }
void SetBlockMeta(const Vector3i & a_Pos, NIBBLETYPE a_MetaData) { SetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z, a_MetaData); }
NIBBLETYPE GetBlockBlockLight(const Vector3i & a_Pos) { return GetBlockBlockLight( a_Pos.x, a_Pos.y, a_Pos.z); }
// tolua_end
/** Writes the block area into the specified coords.