2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "World.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cRedstoneHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
cRedstoneHandler() = default;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(cRedstoneHandler);
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
struct PoweringData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PoweringData(BLOCKTYPE a_PoweringBlock, unsigned char a_PowerLevel) :
|
|
|
|
PoweringBlock(a_PoweringBlock),
|
|
|
|
PowerLevel(a_PowerLevel)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PoweringData(void) :
|
|
|
|
PoweringBlock(E_BLOCK_AIR),
|
|
|
|
PowerLevel(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BLOCKTYPE PoweringBlock;
|
|
|
|
unsigned char PowerLevel;
|
|
|
|
|
|
|
|
inline friend bool operator < (const PoweringData & a_Lhs, const PoweringData & a_Rhs)
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(a_Lhs.PowerLevel < a_Rhs.PowerLevel) ||
|
|
|
|
(
|
|
|
|
(a_Lhs.PowerLevel == a_Rhs.PowerLevel) &&
|
|
|
|
((a_Lhs.PoweringBlock == E_BLOCK_REDSTONE_WIRE) && (a_Rhs.PoweringBlock != E_BLOCK_REDSTONE_WIRE))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline friend bool operator == (const PoweringData & a_Lhs, const PoweringData & a_Rhs)
|
|
|
|
{
|
|
|
|
return (a_Lhs.PowerLevel == a_Rhs.PowerLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline friend bool operator != (const PoweringData & a_Lhs, const PoweringData & a_Rhs)
|
|
|
|
{
|
|
|
|
return !operator ==(a_Lhs, a_Rhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-07 04:25:34 -04:00
|
|
|
virtual cVector3iArray Update(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const = 0;
|
|
|
|
virtual unsigned char GetPowerDeliveredToPosition(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType) const = 0;
|
|
|
|
virtual unsigned char GetPowerLevel(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const = 0;
|
|
|
|
virtual cVector3iArray GetValidSourcePositions(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const = 0;
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
// Force a virtual destructor
|
|
|
|
virtual ~cRedstoneHandler() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
template <class Container>
|
2017-07-14 22:09:55 -04:00
|
|
|
static Container StaticAppend(const Container & a_Lhs, const Container & a_Rhs)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
Container ToReturn = a_Lhs;
|
|
|
|
std::copy(a_Rhs.begin(), a_Rhs.end(), std::back_inserter(ToReturn));
|
|
|
|
return ToReturn;
|
|
|
|
}
|
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
inline static Vector3i OffsetYP()
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
return Vector3i(0, 1, 0);
|
|
|
|
}
|
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
inline static Vector3i OffsetYM()
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
return Vector3i(0, -1, 0);
|
|
|
|
}
|
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
static cVector3iArray GetAdjustedRelatives(Vector3i a_Position, cVector3iArray a_Relatives)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2017-07-14 22:09:55 -04:00
|
|
|
for (auto & Entry : a_Relatives)
|
|
|
|
{
|
|
|
|
Entry += a_Position;
|
|
|
|
}
|
|
|
|
return a_Relatives;
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
inline static cVector3iArray GetRelativeAdjacents()
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ 1, 0, 0 },
|
|
|
|
{ -1, 0, 0 },
|
|
|
|
{ 0, 1, 0 },
|
|
|
|
{ 0, -1, 0 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 0, 0, -1 },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
inline static cVector3iArray GetRelativeLaterals()
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ 1, 0, 0 },
|
|
|
|
{ -1, 0, 0 },
|
|
|
|
{ 0, 0, 1 },
|
|
|
|
{ 0, 0, -1 },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|