1
0
cuberite-2a/src/Map.h

221 lines
4.6 KiB
C
Raw Normal View History

2014-02-13 10:13:09 -05:00
// Map.h
// Implementation of in-game coloured maps
#pragma once
#include "BlockID.h"
class cClientHandle;
class cWorld;
2014-02-15 13:06:47 -05:00
class cPlayer;
2015-06-30 10:50:15 -04:00
class cItemFrame;
2014-02-18 13:50:08 -05:00
class cMap;
2014-02-20 09:38:37 -05:00
/** Encapsulates a map decorator.
A map decorator represents an object drawn on the map that can move freely.
(e.g. player trackers and item frame pointers)
Excluding manually placed decorators,
decorators are automatically managed (allocated and freed) by their parent cMap instance.
*/
2015-06-30 10:50:15 -04:00
struct cMapDecorator
2014-02-18 13:50:08 -05:00
{
public:
2014-02-19 08:28:48 -05:00
2015-06-30 10:50:15 -04:00
enum class eType
2014-02-18 13:50:08 -05:00
{
E_TYPE_PLAYER = 0x00,
E_TYPE_ITEM_FRAME = 0x01,
2014-02-19 08:28:48 -05:00
/** Player outside of the boundaries of the map. */
2014-02-18 13:50:08 -05:00
E_TYPE_PLAYER_OUTSIDE = 0x06
};
2015-06-30 10:50:15 -04:00
cMapDecorator(eType a_Type, unsigned int a_X, unsigned int a_Z, int a_Rot) :
m_Type(a_Type),
m_PixelX(a_X),
m_PixelZ(a_Z),
m_Rot(a_Rot)
{
}
2014-02-18 13:50:08 -05:00
public:
unsigned int GetPixelX(void) const { return m_PixelX; }
unsigned int GetPixelZ(void) const { return m_PixelZ; }
2014-02-19 08:28:48 -05:00
2015-06-30 10:50:15 -04:00
int GetRot(void) const { return m_Rot; }
2014-02-18 13:50:08 -05:00
eType GetType(void) const { return m_Type; }
2015-06-30 10:50:15 -04:00
private:
2014-02-18 13:50:08 -05:00
eType m_Type;
unsigned int m_PixelX;
unsigned int m_PixelZ;
2015-06-30 10:50:15 -04:00
int m_Rot;
2014-02-19 08:28:48 -05:00
2014-02-18 13:50:08 -05:00
};
2014-02-13 10:13:09 -05:00
2014-02-14 09:21:16 -05:00
// tolua_begin
2014-02-19 08:28:48 -05:00
/** Encapsulates an in-game world map. */
2014-02-13 10:13:09 -05:00
class cMap
{
public:
enum eBaseColor
{
E_BASE_COLOR_TRANSPARENT = 0, /* Air */
E_BASE_COLOR_LIGHT_GREEN = 4, /* Grass */
2015-06-30 10:50:15 -04:00
E_BASE_COLOR_LIGHT_BLUE = 5,
E_BASE_COLOR_LIGHT_BROWN = 8, /* Sand */
E_BASE_COLOR_GRAY_1 = 12, /* Cloth */
E_BASE_COLOR_RED = 16, /* TNT */
E_BASE_COLOR_PALE_BLUE = 20, /* Ice */
E_BASE_COLOR_GRAY_2 = 24, /* Iron */
E_BASE_COLOR_DARK_GREEN = 28, /* Foliage */
E_BASE_COLOR_WHITE = 32, /* Snow */
E_BASE_COLOR_LIGHT_GRAY = 36, /* Clay */
E_BASE_COLOR_BROWN = 40, /* Dirt */
E_BASE_COLOR_DARK_GRAY = 44, /* Stone */
E_BASE_COLOR_BLUE = 48, /* Water */
E_BASE_COLOR_DARK_BROWN = 52 /* Wood */
};
2014-02-13 10:13:09 -05:00
typedef Byte ColorID;
2014-02-14 09:21:16 -05:00
// tolua_end
2014-02-13 10:13:09 -05:00
typedef std::vector<ColorID> cColorList;
2015-06-30 10:50:15 -04:00
typedef std::vector<cClientHandle *> cMapClientList;
typedef std::vector<cMapDecorator> cMapDecoratorList;
2014-02-13 10:13:09 -05:00
2014-02-14 09:21:16 -05:00
/** Construct an empty map. */
2014-02-13 14:36:24 -05:00
cMap(unsigned int a_ID, cWorld * a_World);
/** Construct an empty map at the specified coordinates. */
2014-02-13 10:13:09 -05:00
cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3);
2015-06-30 10:50:15 -04:00
/** Sends a map update to all registered clients
Clears the list holding registered clients and decorators */
void Tick();
2014-02-13 10:13:09 -05:00
2014-02-15 13:06:47 -05:00
/** Update a circular region with the specified radius and center (in pixels). */
void UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius);
2014-02-19 08:28:48 -05:00
/** Update a circular region around the specified player. */
2014-02-15 13:06:47 -05:00
void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius);
/** Send next update packet to the specified player and remove invalid decorators / clients. */
2014-02-18 13:50:08 -05:00
void UpdateClient(cPlayer * a_Player);
2014-02-17 09:27:12 -05:00
2014-02-14 09:21:16 -05:00
// tolua_begin
2014-02-13 10:13:09 -05:00
void Resize(unsigned int a_Width, unsigned int a_Height);
void SetPosition(int a_CenterX, int a_CenterZ);
2015-06-30 10:50:15 -04:00
void SetScale(unsigned int a_Scale) { m_Scale = a_Scale; }
2014-02-13 10:13:09 -05:00
2014-02-22 06:59:49 -05:00
bool SetPixel(unsigned int a_X, unsigned int a_Z, ColorID a_Data);
ColorID GetPixel(unsigned int a_X, unsigned int a_Z);
2014-02-13 10:13:09 -05:00
unsigned int GetWidth (void) const { return m_Width; }
unsigned int GetHeight(void) const { return m_Height; }
unsigned int GetScale(void) const { return m_Scale; }
int GetCenterX(void) const { return m_CenterX; }
int GetCenterZ(void) const { return m_CenterZ; }
unsigned int GetID(void) const { return m_ID; }
cWorld * GetWorld(void) { return m_World; }
2014-02-15 13:06:47 -05:00
AString GetName(void) { return m_Name; }
2014-02-13 10:13:09 -05:00
eDimension GetDimension(void) const;
unsigned int GetNumPixels(void) const;
2014-02-15 13:06:47 -05:00
unsigned int GetPixelWidth(void) const;
2014-02-13 10:13:09 -05:00
2014-02-14 09:21:16 -05:00
// tolua_end
2015-06-30 10:50:15 -04:00
const cMapDecorator CreateDecorator(const cEntity * a_TrackedEntity);
const cMapDecoratorList GetDecorators(void) const { return m_Decorators; }
2014-02-22 06:59:49 -05:00
const cColorList & GetData(void) const { return m_Data; }
2014-02-23 06:25:02 -05:00
static const char * GetClassStatic(void) // Needed for ManualBindings's DoWith templates
{
return "cMap";
}
2015-03-19 11:24:32 -04:00
const char * GetClass(void) // Needed for ManualBindings' DoWith templates
{
return "cMap";
}
2014-02-13 10:13:09 -05:00
private:
2014-02-14 09:21:16 -05:00
/** Update the specified pixel. */
2014-02-17 09:27:12 -05:00
bool UpdatePixel(unsigned int a_X, unsigned int a_Z);
2014-02-14 09:21:16 -05:00
2014-02-13 10:13:09 -05:00
unsigned int m_ID;
unsigned int m_Width;
unsigned int m_Height;
/** The zoom level, 2^scale square blocks per pixel */
unsigned int m_Scale;
int m_CenterX;
int m_CenterZ;
/** Column-major array of colours */
cColorList m_Data;
cWorld * m_World;
2015-06-30 10:50:15 -04:00
cMapClientList m_ClientsInCurrentTick;
2014-02-17 09:27:12 -05:00
2015-06-30 10:50:15 -04:00
cMapDecoratorList m_Decorators;
2014-02-15 13:06:47 -05:00
AString m_Name;
2014-02-13 10:13:09 -05:00
friend class cMapSerializer;
}; // tolua_export
2014-02-21 08:26:33 -05:00