1
0

Added cFloater class.

This commit is contained in:
STRWarrior 2013-12-19 17:32:06 +01:00
parent 56076c3baa
commit 86bfed735e
3 changed files with 90 additions and 0 deletions

View File

@ -75,6 +75,7 @@ public:
etTNT,
etProjectile,
etExpOrb,
etFloater,
// Common variations
etMob = etMonster, // DEPRECATED, use etMonster instead!
@ -129,6 +130,8 @@ public:
bool IsBoat (void) const { return (m_EntityType == etBoat); }
bool IsTNT (void) const { return (m_EntityType == etTNT); }
bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); }
bool IsFloater (void) const { return (m_EntityType == etFloater); }
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
virtual bool IsA(const char * a_ClassName) const;

58
src/Entities/Floater.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "Globals.h"
#include "Floater.h"
#include "Player.h"
#include "../Clienthandle.h"
cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID) :
cEntity(etFloater, a_X, a_Y, a_Z, 0.98, 0.98),
m_PlayerID(a_PlayerID),
m_CanPickupItem(false),
m_PickupCountDown(0)
{
SetSpeed(a_Speed);
}
void cFloater::SpawnOn(cClientHandle & a_Client)
{
a_Client.SendSpawnObject(*this, 90, m_PlayerID, 0, 0);
}
void cFloater::Tick(float a_Dt, cChunk & a_Chunk)
{
HandlePhysics(a_Dt, a_Chunk);
if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())))
{
if (m_World->GetTickRandomNumber(100) == 0)
{
SetSpeedY(-1);
m_CanPickupItem = true;
m_PickupCountDown = 20;
LOGD("Floater %i can be picked up", GetUniqueID());
}
else
{
SetSpeedY(1);
}
}
SetSpeedX(GetSpeedX() * 0.95);
SetSpeedZ(GetSpeedZ() * 0.95);
if (CanPickup())
{
m_PickupCountDown--;
if (m_PickupCountDown == 0)
{
m_CanPickupItem = false;
LOGD("The fish is gone. Floater %i can not pick an item up.", GetUniqueID());
}
}
BroadcastMovementUpdate();
}

29
src/Entities/Floater.h Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include "Entity.h"
class cFloater :
public cEntity
{
typedef cFloater super;
public:
cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID);
virtual void SpawnOn(cClientHandle & a_Client) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
bool CanPickup(void) const { return m_CanPickupItem; }
protected:
Vector3d m_Speed;
int m_PickupCountDown;
int m_PlayerID;
bool m_CanPickupItem;
} ;