a4dbb5c582
* Change reinterpret_cast -> static_cast wherever possible * Remove more unnecessary `const_cast`s. reinterpret_casts should be avoided for the same reason as c-style casts - they don't do any type-checking. reinterpret_cast was mainly being used for down-casting in inheritance hierarchies but static_cast works just as well while also making sure that there is actually an inheritance relationship there.
94 lines
1.8 KiB
C++
94 lines
1.8 KiB
C++
|
|
// SignEntity.cpp
|
|
|
|
// Implements the cSignEntity class representing a single sign in the world
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
#include "json/value.h"
|
|
#include "SignEntity.h"
|
|
#include "../ClientHandle.h"
|
|
|
|
|
|
|
|
|
|
|
|
cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World):
|
|
Super(a_BlockType, a_BlockMeta, a_BlockX, a_BlockY, a_BlockZ, a_World)
|
|
{
|
|
ASSERT((a_BlockType == E_BLOCK_WALLSIGN) || (a_BlockType == E_BLOCK_SIGN_POST));
|
|
ASSERT(cChunkDef::IsValidHeight(a_BlockY));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cSignEntity::CopyFrom(const cBlockEntity & a_Src)
|
|
{
|
|
Super::CopyFrom(a_Src);
|
|
auto & src = static_cast<const cSignEntity &>(a_Src);
|
|
for (size_t i = 0; i < ARRAYCOUNT(m_Line); ++i)
|
|
{
|
|
m_Line[i] = src.m_Line[i];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool cSignEntity::UsedBy(cPlayer * a_Player)
|
|
{
|
|
UNUSED(a_Player);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cSignEntity::SetLines(const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4)
|
|
{
|
|
m_Line[0] = a_Line1;
|
|
m_Line[1] = a_Line2;
|
|
m_Line[2] = a_Line3;
|
|
m_Line[3] = a_Line4;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cSignEntity::SetLine(int a_Index, const AString & a_Line)
|
|
{
|
|
if ((a_Index < 0) || (a_Index >= static_cast<int>(ARRAYCOUNT(m_Line))))
|
|
{
|
|
LOGWARNING("%s: setting a non-existent line %d (value \"%s\"", __FUNCTION__, a_Index, a_Line.c_str());
|
|
return;
|
|
}
|
|
m_Line[a_Index] = a_Line;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AString cSignEntity::GetLine(int a_Index) const
|
|
{
|
|
if ((a_Index < 0) || (a_Index >= static_cast<int>(ARRAYCOUNT(m_Line))))
|
|
{
|
|
LOGWARNING("%s: requesting a non-existent line %d", __FUNCTION__, a_Index);
|
|
return "";
|
|
}
|
|
return m_Line[a_Index];
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cSignEntity::SendTo(cClientHandle & a_Client)
|
|
{
|
|
a_Client.SendUpdateSign(m_PosX, m_PosY, m_PosZ, m_Line[0], m_Line[1], m_Line[2], m_Line[3]);
|
|
}
|