2014-03-01 10:04:17 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
// fwd:
|
|
|
|
class cBlockHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-02 03:50:24 -05:00
|
|
|
// tolua_begin
|
2014-03-01 14:34:19 -05:00
|
|
|
class cBlockInfo
|
2014-03-01 10:04:17 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-06-25 02:07:06 -04:00
|
|
|
/** Returns the associated BlockInfo structure for the specified block type. */
|
2014-09-17 13:40:10 -04:00
|
|
|
|
|
|
|
/** This accessor makes sure that the cBlockInfo structures are properly initialized exactly once.
|
2014-09-25 10:45:39 -04:00
|
|
|
It does so by using the C++ singleton approximation - storing the actual singleton as the function's static variable.
|
|
|
|
It works only if it is called for the first time before the app spawns other threads. */
|
2014-09-17 13:40:10 -04:00
|
|
|
static cBlockInfo & Get(BLOCKTYPE a_Type)
|
|
|
|
{
|
|
|
|
static cBlockInfo ms_Info[256];
|
|
|
|
static bool IsBlockInfoInitialized = false;
|
|
|
|
if (!IsBlockInfoInitialized)
|
|
|
|
{
|
|
|
|
cBlockInfo::Initialize(ms_Info);
|
|
|
|
IsBlockInfoInitialized = true;
|
|
|
|
}
|
|
|
|
return ms_Info[a_Type];
|
|
|
|
}
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** How much light do the blocks emit on their own? */
|
2014-03-01 10:04:17 -05:00
|
|
|
NIBBLETYPE m_LightValue;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** How much light do the blocks consume? */
|
2014-03-01 10:04:17 -05:00
|
|
|
NIBBLETYPE m_SpreadLightFalloff;
|
|
|
|
|
2014-03-01 14:34:19 -05:00
|
|
|
/** Is a block completely transparent? (light doesn't get decreased(?)) */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_Transparent;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** Is a block destroyed after a single hit? */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_OneHitDig;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** Can a piston break this block? */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_PistonBreakable;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** Can this block hold snow atop? */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_IsSnowable;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** Is this block solid (player cannot walk through)? */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_IsSolid;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
2014-03-02 03:50:24 -05:00
|
|
|
/** Does this block fully occupy its voxel - is it a 'full' block? */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_FullyOccupiesVoxel;
|
|
|
|
|
2014-07-29 16:31:31 -04:00
|
|
|
/** Can a finisher change it? */
|
|
|
|
bool m_CanBeTerraformed;
|
|
|
|
|
2015-11-10 08:02:07 -05:00
|
|
|
/** Block height */
|
|
|
|
float m_BlockHeight;
|
|
|
|
|
2014-09-09 10:00:26 -04:00
|
|
|
/** Sound when placing this block */
|
|
|
|
AString m_PlaceSound;
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
// tolua_end
|
|
|
|
|
|
|
|
/** Associated block handler. */
|
|
|
|
cBlockHandler * m_Handler;
|
|
|
|
|
|
|
|
// tolua_begin
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2014-03-02 09:24:09 -05:00
|
|
|
inline static NIBBLETYPE GetLightValue (BLOCKTYPE a_Type) { return Get(a_Type).m_LightValue; }
|
|
|
|
inline static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE a_Type) { return Get(a_Type).m_SpreadLightFalloff; }
|
|
|
|
inline static bool IsTransparent (BLOCKTYPE a_Type) { return Get(a_Type).m_Transparent; }
|
|
|
|
inline static bool IsOneHitDig (BLOCKTYPE a_Type) { return Get(a_Type).m_OneHitDig; }
|
|
|
|
inline static bool IsPistonBreakable (BLOCKTYPE a_Type) { return Get(a_Type).m_PistonBreakable; }
|
|
|
|
inline static bool IsSnowable (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSnowable; }
|
|
|
|
inline static bool IsSolid (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid; }
|
|
|
|
inline static bool FullyOccupiesVoxel (BLOCKTYPE a_Type) { return Get(a_Type).m_FullyOccupiesVoxel; }
|
2014-07-29 16:31:31 -04:00
|
|
|
inline static bool CanBeTerraformed (BLOCKTYPE a_Type) { return Get(a_Type).m_CanBeTerraformed; }
|
2015-11-10 08:02:07 -05:00
|
|
|
inline static float GetBlockHeight (BLOCKTYPE a_Type) { return Get(a_Type).m_BlockHeight; }
|
2014-09-09 10:00:26 -04:00
|
|
|
inline static AString GetPlaceSound (BLOCKTYPE a_Type) { return Get(a_Type).m_PlaceSound; }
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2014-03-02 03:50:24 -05:00
|
|
|
// tolua_end
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
inline static cBlockHandler * GetHandler (BLOCKTYPE a_Type) { return Get(a_Type).m_Handler; }
|
|
|
|
|
2014-03-01 10:04:17 -05:00
|
|
|
protected:
|
2014-06-25 02:07:06 -04:00
|
|
|
/** Storage for all the BlockInfo structures. */
|
|
|
|
typedef cBlockInfo cBlockInfoArray[256];
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2014-06-25 02:07:06 -04:00
|
|
|
/** Creates a default BlockInfo structure, initializes all values to their defaults */
|
2014-09-17 13:40:10 -04:00
|
|
|
cBlockInfo()
|
|
|
|
: m_LightValue(0x00)
|
|
|
|
, m_SpreadLightFalloff(0x0f)
|
|
|
|
, m_Transparent(false)
|
|
|
|
, m_OneHitDig(false)
|
|
|
|
, m_PistonBreakable(false)
|
|
|
|
, m_IsSnowable(false)
|
|
|
|
, m_IsSolid(true)
|
|
|
|
, m_FullyOccupiesVoxel(false)
|
|
|
|
, m_CanBeTerraformed(false)
|
2015-11-10 08:02:07 -05:00
|
|
|
, m_BlockHeight(1.0)
|
2014-09-17 13:40:10 -04:00
|
|
|
, m_PlaceSound("")
|
2014-10-20 16:55:07 -04:00
|
|
|
, m_Handler(nullptr)
|
2014-09-17 13:40:10 -04:00
|
|
|
{}
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2014-06-25 02:07:06 -04:00
|
|
|
/** Cleans up the stored values */
|
|
|
|
~cBlockInfo();
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2014-06-25 02:07:06 -04:00
|
|
|
/** Initializes the specified BlockInfo structures with block-specific values. */
|
|
|
|
static void Initialize(cBlockInfoArray & a_BlockInfos);
|
2014-07-17 13:13:23 -04:00
|
|
|
}; // tolua_export
|
2014-03-01 10:04:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
|
|
|
|
// Shortcut to get the blockhandler for a specific block
|
|
|
|
inline cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
|
|
|
|
{
|
|
|
|
return cBlockInfo::Get(a_BlockType).m_Handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|