summaryrefslogtreecommitdiffstats
path: root/src/Map.h
blob: 805dfb8451c547f37755373c2c50642bafcdd770 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

// Map.h

// Implementation of in-game coloured maps





#pragma once





#include "BlockID.h"





class cClientHandle;
class cWorld;
class cPlayer;





// tolua_begin
class cMap
{
public:

	typedef Byte ColorID;

	// tolua_end

	typedef std::vector<ColorID> cColorList;

	static const unsigned int DEFAULT_RADIUS = 128;


public:

	/** Construct an empty map. */
	cMap(unsigned int a_ID, cWorld * a_World);

	cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3);

	/** Send this map to the specified client. */
	void SendTo(cClientHandle & a_Client);

	/** Update a circular region with the specified radius and center (in pixels). */
	void UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius);

	void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius);

	void UpdateTrackedPlayers(void);

	void AddTrackedPlayer(cPlayer * a_Player);

	// tolua_begin

	/** Erase pixel data */
	void EraseData(void);

	void Resize(unsigned int a_Width, unsigned int a_Height);

	void SetPosition(int a_CenterX, int a_CenterZ);

	void SetScale(unsigned int a_Scale);

	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; }

	AString GetName(void) { return m_Name; }

	eDimension GetDimension(void) const;

	const cColorList & GetData(void) const { return m_Data; }

	unsigned int GetNumPixels(void) const;

	unsigned int GetPixelWidth(void) const;

	// tolua_end


private:

	/** Update the specified pixel. */
	bool UpdatePixel(unsigned int a_X, unsigned int a_Z);

	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;

	typedef std::set<cPlayer*> cTrackedPlayerList;

	cTrackedPlayerList m_TrackedPlayers;

	AString m_Name;

	friend class cMapSerializer;

};