2014-04-26 20:50:05 -04:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2014-04-27 20:03:06 -04:00
|
|
|
#include "FireworkEntity.h"
|
2014-04-26 20:50:05 -04:00
|
|
|
#include "../World.h"
|
|
|
|
#include "../Chunk.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) :
|
2014-04-27 20:03:06 -04:00
|
|
|
super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25),
|
2014-10-21 15:25:52 -04:00
|
|
|
m_TicksToExplosion(a_Item.m_FireworkItem.m_FlightTimeInTicks),
|
2014-04-27 20:03:06 -04:00
|
|
|
m_FireworkItem(a_Item)
|
2014-04-26 20:50:05 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
void cFireworkEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2014-04-26 20:50:05 -04:00
|
|
|
{
|
|
|
|
int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width;
|
|
|
|
int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width;
|
|
|
|
int PosY = POSY_TOINT;
|
|
|
|
|
|
|
|
if ((PosY < 0) || (PosY >= cChunkDef::Height))
|
|
|
|
{
|
2014-10-21 15:25:52 -04:00
|
|
|
AddSpeedY(1);
|
2015-01-18 05:02:17 -05:00
|
|
|
AddPosition(GetSpeed() * (static_cast<double>(a_Dt.count()) / 1000));
|
2014-10-21 15:25:52 -04:00
|
|
|
return;
|
2014-04-26 20:50:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_IsInGround)
|
|
|
|
{
|
|
|
|
if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
m_IsInGround = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddSpeedY(1);
|
2015-01-18 05:02:17 -05:00
|
|
|
AddPosition(GetSpeed() * (static_cast<double>(a_Dt.count()) / 1000));
|
2014-04-26 20:50:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
void cFireworkEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2014-04-26 20:50:05 -04:00
|
|
|
{
|
|
|
|
super::Tick(a_Dt, a_Chunk);
|
|
|
|
|
2014-10-21 15:25:52 -04:00
|
|
|
if (m_TicksToExplosion <= 0)
|
2014-04-26 20:50:05 -04:00
|
|
|
{
|
2014-10-21 15:25:52 -04:00
|
|
|
// TODO: Notify the plugins
|
2014-04-26 20:50:05 -04:00
|
|
|
m_World->BroadcastEntityStatus(*this, esFireworkExploding);
|
|
|
|
Destroy();
|
2014-10-21 15:25:52 -04:00
|
|
|
return;
|
2014-04-26 20:50:05 -04:00
|
|
|
}
|
|
|
|
|
2014-10-21 15:25:52 -04:00
|
|
|
m_TicksToExplosion -= 1;
|
2014-04-27 12:42:31 -04:00
|
|
|
}
|