summaryrefslogtreecommitdiffstats
path: root/source/cPawn.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-13 22:47:03 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-13 22:47:03 +0100
commit4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c (patch)
treefebea3ecd89c0d4aa83924e430bf11366d754733 /source/cPawn.cpp
parentNew makefile with automatic *.cpp sourcefile import, automatic header file dependencies and switchable debug / release configuration. gnumake-specific :( (diff)
downloadcuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar
cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.gz
cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.bz2
cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.lz
cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.xz
cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.tar.zst
cuberite-4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c.zip
Diffstat (limited to 'source/cPawn.cpp')
-rw-r--r--source/cPawn.cpp134
1 files changed, 100 insertions, 34 deletions
diff --git a/source/cPawn.cpp b/source/cPawn.cpp
index fa79fdcb9..0e169e676 100644
--- a/source/cPawn.cpp
+++ b/source/cPawn.cpp
@@ -17,8 +17,16 @@
#include "packets/cPacket_EntityStatus.h"
#include "packets/cPacket_Metadata.h"
+
+
+
+
CLASS_DEFINITION( cPawn, cEntity )
+
+
+
+
cPawn::cPawn()
: cEntity( 0, 0, 0 )
, m_LastPosX( 0.0 )
@@ -34,16 +42,28 @@ cPawn::cPawn()
SetMaxFoodLevel(125);
}
+
+
+
+
cPawn::~cPawn()
{
}
+
+
+
+
void cPawn::Heal( int a_Health )
{
(void)a_Health;
}
+
+
+
+
void cPawn::TakeDamage( int a_Damage, cEntity* a_Instigator )
{
TakeDamageInfo TDI;
@@ -51,8 +71,6 @@ void cPawn::TakeDamage( int a_Damage, cEntity* a_Instigator )
TDI.Instigator = a_Instigator;
cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_TAKE_DAMAGE, 2, this, &TDI );
-
-
if( TDI.Damage == 0 ) return;
if( m_Health <= 0 ) return; // Can't take damage if already dead
@@ -62,14 +80,19 @@ void cPawn::TakeDamage( int a_Damage, cEntity* a_Instigator )
cPacket_EntityStatus Status;
Status.m_UniqueID = GetUniqueID();
Status.m_Status = cPacket_EntityStatus::STATUS_TAKEDAMAGE;
- cChunk* Chunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
- if( Chunk )
- Chunk->Broadcast( Status );
+ cChunkPtr Chunk = GetWorld()->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ );
+ Chunk->Broadcast( Status );
- if( m_Health <= 0 )
+ if (m_Health <= 0)
+ {
KilledBy( TDI.Instigator );
+ }
}
+
+
+
+
void cPawn::KilledBy( cEntity* a_Killer )
{
m_Health = 0;
@@ -82,16 +105,23 @@ void cPawn::KilledBy( cEntity* a_Killer )
cPacket_EntityStatus Status;
Status.m_UniqueID = GetUniqueID();
Status.m_Status = cPacket_EntityStatus::STATUS_DIE;
- cChunk* Chunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
- if( Chunk )
- Chunk->Broadcast( Status ); // Die
+ cChunkPtr Chunk = GetWorld()->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ );
+ Chunk->Broadcast( Status ); // Die
}
+
+
+
+
void cPawn::TeleportTo( cEntity* a_Entity )
{
TeleportTo( a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ() );
}
+
+
+
+
void cPawn::TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ )
{
SetPosition( a_PosX, a_PosY, a_PosZ );
@@ -99,31 +129,41 @@ void cPawn::TeleportTo( const double & a_PosX, const double & a_PosY, const doub
cPacket_TeleportEntity TeleportEntity( this );
cRoot::Get()->GetServer()->Broadcast( TeleportEntity );
-
}
+
+
+
+
void cPawn::Tick(float a_Dt)
{
CheckMetaDataBurn(); //Check to see if pawn should burn based on block they are on
- if(GetMetaData() == BURNING)
+ if (GetMetaData() == BURNING)
+ {
InStateBurning(a_Dt);
-
+ }
}
+
+
+
+
void cPawn::SetMetaData(MetaData a_MetaData)
{
- cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
+ cChunkPtr InChunk = GetWorld()->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ );
- if(InChunk)
- { //Broadcast new status to clients in the chunk
- m_MetaData = a_MetaData;
- cPacket_Metadata md(a_MetaData, GetUniqueID());
- InChunk->Broadcast(md);
- }
+ //Broadcast new status to clients in the chunk
+ m_MetaData = a_MetaData;
+ cPacket_Metadata md(a_MetaData, GetUniqueID());
+ InChunk->Broadcast(md);
}
+
+
+
+
//----Change Entity MetaData
void cPawn::CheckMetaDataBurn()
{
@@ -131,49 +171,67 @@ void cPawn::CheckMetaDataBurn()
char BlockAbove = GetWorld()->GetBlock((int) m_Pos->x, (int) m_Pos->y + 1, (int) m_Pos->z);
char BlockBelow = GetWorld()->GetBlock((int) m_Pos->x, (int) m_Pos->y - 1, (int) m_Pos->z);
- if(GetMetaData() == BURNING
- && (IsBlockWater(Block)
- || IsBlockWater(BlockAbove)
- || IsBlockWater(BlockBelow)))
+ if (
+ (GetMetaData() == BURNING) &&
+ (IsBlockWater(Block) || IsBlockWater(BlockAbove) || IsBlockWater(BlockBelow))
+ )
{
SetMetaData(NORMAL);
- }else if(m_bBurnable && GetMetaData() != BURNING
- && (IsBlockLava(Block) || Block == E_BLOCK_FIRE
- || IsBlockLava(BlockAbove) || BlockAbove == E_BLOCK_FIRE
- || IsBlockLava(BlockBelow) || BlockBelow == E_BLOCK_FIRE)) {
+ }
+ else if (
+ m_bBurnable &&
+ (GetMetaData() != BURNING) &&
+ (
+ IsBlockLava(Block) || (Block == E_BLOCK_FIRE) ||
+ IsBlockLava(BlockAbove) || (BlockAbove == E_BLOCK_FIRE) ||
+ IsBlockLava(BlockBelow) || (BlockBelow == E_BLOCK_FIRE)
+ )
+ )
+ {
SetMetaData(BURNING);
}
}
+
+
+
+
//What to do if On fire
void cPawn::InStateBurning(float a_Dt)
{
m_FireDamageInterval += a_Dt;
char Block = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z );
char BlockAbove = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y + 1, (int)m_Pos->z );
- if(m_FireDamageInterval > 800) {
+ if (m_FireDamageInterval > 800)
+ {
m_FireDamageInterval = 0;
TakeDamage(1, this);
m_BurnPeriod++;
- if(IsBlockLava(Block) || Block == E_BLOCK_FIRE
- || IsBlockLava(BlockAbove) || BlockAbove == E_BLOCK_FIRE) {
+ if (IsBlockLava(Block) || Block == E_BLOCK_FIRE
+ || IsBlockLava(BlockAbove) || BlockAbove == E_BLOCK_FIRE)
+ {
m_BurnPeriod = 0;
TakeDamage(6, this);
- }else{
+ }
+ else
+ {
TakeDamage(1, this);
}
- if(m_BurnPeriod > 7) {
+ if (m_BurnPeriod > 7)
+ {
SetMetaData(NORMAL);
m_BurnPeriod = 0;
-
}
}
-
}
+
+
+
+
void cPawn::SetMaxHealth(short a_MaxHealth)
{
this->m_MaxHealth = a_MaxHealth;
@@ -182,6 +240,10 @@ void cPawn::SetMaxHealth(short a_MaxHealth)
m_Health = a_MaxHealth;
}
+
+
+
+
void cPawn::SetMaxFoodLevel(short a_MaxFoodLevel)
{
m_MaxFoodLevel = a_MaxFoodLevel;
@@ -189,3 +251,7 @@ void cPawn::SetMaxFoodLevel(short a_MaxFoodLevel)
//Reset food level
m_FoodLevel = a_MaxFoodLevel;
}
+
+
+
+