2013-08-22 02:55:58 -04:00
|
|
|
|
|
|
|
// ProjectileEntity.cpp
|
|
|
|
|
|
|
|
// Implements the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "ProjectileEntity.h"
|
2013-08-22 03:07:12 -04:00
|
|
|
#include "../ClientHandle.h"
|
2013-08-25 15:31:35 -04:00
|
|
|
#include "Player.h"
|
2013-08-22 02:55:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// cProjectileEntity:
|
|
|
|
|
|
|
|
cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, double a_Width, double a_Height) :
|
|
|
|
super(etProjectile, a_X, a_Y, a_Z, a_Width, a_Height),
|
2013-08-22 16:31:15 -04:00
|
|
|
m_ProjectileKind(a_Kind),
|
2013-08-22 02:55:58 -04:00
|
|
|
m_Creator(a_Creator)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height) :
|
|
|
|
super(etProjectile, a_Pos.x, a_Pos.y, a_Pos.z, a_Width, a_Height),
|
2013-08-22 16:31:15 -04:00
|
|
|
m_ProjectileKind(a_Kind),
|
2013-08-22 02:55:58 -04:00
|
|
|
m_Creator(a_Creator)
|
|
|
|
{
|
|
|
|
SetSpeed(a_Speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d * a_Speed)
|
|
|
|
{
|
|
|
|
Vector3d Speed;
|
|
|
|
if (a_Speed != NULL)
|
|
|
|
{
|
|
|
|
Speed = *a_Speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (a_Kind)
|
|
|
|
{
|
|
|
|
case pkArrow: return new cArrowEntity(a_Creator, a_X, a_Y, a_Z, Speed);
|
|
|
|
// TODO: the rest
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGWARNING("%s: Unknown kind: %d", __FUNCTION__, a_Kind);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-22 16:31:15 -04:00
|
|
|
AString cProjectileEntity::GetMCAClassName(void) const
|
|
|
|
{
|
|
|
|
switch (m_ProjectileKind)
|
|
|
|
{
|
|
|
|
case pkArrow: return "Arrow";
|
|
|
|
case pkSnowball: return "Snowball";
|
|
|
|
case pkEgg: return "Egg";
|
|
|
|
case pkGhastFireball: return "Fireball";
|
|
|
|
case pkFireCharge: return "SmallFireball";
|
|
|
|
case pkEnderPearl: return "ThrownEnderPearl";
|
|
|
|
case pkExpBottle: return "ThrownExpBottle";
|
|
|
|
case pkSplashPotion: return "ThrownPotion";
|
|
|
|
case pkWitherSkull: return "WitherSkull";
|
|
|
|
case pkFishingFloat: return ""; // Unknown, perhaps MC doesn't save this?
|
|
|
|
}
|
|
|
|
ASSERT(!"Unhandled projectile entity kind!");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-22 02:55:58 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// cArrowEntity:
|
|
|
|
|
|
|
|
cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d a_Speed) :
|
2013-08-22 16:31:15 -04:00
|
|
|
super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5),
|
|
|
|
m_PickupState(psNoPickup),
|
|
|
|
m_DamageCoeff(2)
|
2013-08-22 02:55:58 -04:00
|
|
|
{
|
|
|
|
SetSpeed(a_Speed);
|
2013-08-22 16:31:15 -04:00
|
|
|
SetMass(0.1);
|
2013-08-22 02:55:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-25 15:31:35 -04:00
|
|
|
bool cArrowEntity::CanPickup(const cPlayer & a_Player) const
|
|
|
|
{
|
|
|
|
switch (m_PickupState)
|
|
|
|
{
|
|
|
|
case psNoPickup: return false;
|
|
|
|
case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative());
|
|
|
|
case psInCreative: return a_Player.IsGameModeCreative();
|
|
|
|
}
|
|
|
|
ASSERT(!"Unhandled pickup state");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-26 16:27:28 -04:00
|
|
|
void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk)
|
|
|
|
{
|
|
|
|
super::Tick(a_Dt, a_Chunk);
|
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
LOGD("Arrow %d: {%.02f, %.02f, %.02f}", m_UniqueID, GetPosX(), GetPosY(), GetPosZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-22 02:55:58 -04:00
|
|
|
void cArrowEntity::SpawnOn(cClientHandle & a_Client)
|
|
|
|
{
|
2013-08-22 03:07:12 -04:00
|
|
|
a_Client.SendSpawnObject(*this, pkArrow, 0, 0, 0);
|
2013-08-22 02:55:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|