summaryrefslogtreecommitdiff
path: root/src/layer_func.h
blob: 250e79a3d4bff045089dc99b9ae1ccc532d8573e (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* $Id: layer_func.h 2012-09-07 18:11:11 constructor $ */

/*
*	Подробое описание см. в layer.cpp
*/

/** @file layer_func.h Functions related to layer in maps. */

#ifndef LAYER_FUNC_H
#define LAYER_FUNC_H

#include "map_func.h"
#include "viewport_type.h"

/*
*
*	Инициализация "подземелий"
*	Количество слоев "1" равносильно игре без "подземелий"
*
*/
void InstallLayerSystem(uint size_x, uint size_y, uint layer_count);

/*	Корректировка "подземных" слоев 
*	(в будущем слои могут менять высоты -- в пределах соседей) */
void FixUndergroundHeights();

#define FOR_ALL_LAYERS(var) for (uint var = 0; var < LayerCount(); var++)


/**
 * Get the size of the layer along the X
 * @return the number of tiles along the X of the layer
 */
static inline uint LayerSizeX()
{
	extern uint _map_size_x;
	return _map_size_x;
}

/**
 * Get the size of the layer along the Y
 * @return the number of tiles along the Y of the layer
 */
static inline uint LayerSizeY()
{
	extern uint _layer_size_y;
	return _layer_size_y;
}

/**
 * Gets the maximum X coordinate within the map, including MP_VOID
 * @return the maximum X coordinate
 */
static inline uint LayerMaxX()
{
	return LayerSizeX() - 1;
}

/**
 * Gets the maximum Y coordinate within the map, including MP_VOID
 * @return the maximum Y coordinate
 */
static inline uint LayerMaxY()
{
	return LayerSizeY() - 1;
}

/**
 * Get the layer counts
 * @return the number of layers
 */
static inline uint LayerCount()
{
	extern uint _layer_count;
	return _layer_count;
}

/**
 * Get the layer counts
 * @return the number of layers
 */
static inline uint LayerCountLog()
{
	extern uint _layer_count_log;
	return _layer_count_log;
}

/**
 * Get the X component of a tile
 * @param tile the tile to get the X component of
 * @return the X component
 */
static inline uint LayerX(TileIndex tile)
{
	return tile & LayerMaxX();
}

/**
 * Get the Y component of a tile
 * @param tile the tile to get the Y component of
 * @return the Y component
 */
static inline uint LayerY(TileIndex tile)
{
	return (tile >> MapLogX()) & LayerMaxY();
}

static inline uint LayerIndex(TileIndex tile)
{
	return (tile >> MapLogX()) / LayerSizeY();
}

static inline bool IsUnderground(TileIndex tile)
{
	return LayerIndex(tile) != 0;
}

/**
*	Размер слоя. 
*	Можно прибавить к клетке, чтобы получить клетку ниже
*/
static inline uint LayerSize()
{
	extern uint _layer_size;
	return _layer_size;
}

/**
 * Ищем клетку поверхности для данной (самую верхнюю клетку)
 * @param tile the tile to get the Y component of
 * @return the Y component
 */
static inline uint TopTile(TileIndex tile)
{
	uint layer = LayerIndex(tile);
	return (tile - layer * LayerSize());
}

/*	Определить верхняя ли клеточка очень просто	*/
static inline bool IsTopTile(TileIndex tile)
{
	return (tile < LayerSize());
}

/*	Ищет клетку над данной. (Для самой верхней вернет нижнюю??)
*/
static inline uint UpTile(TileIndex tile)
{
	return TILE_MASK(tile - LayerSize());
}

/*	Ищет клетку под данной. (Для самой нижней вернет верхнюю??)
*/
static inline uint DownTile(TileIndex tile)
{
	return TILE_MASK(tile + LayerSize());
}

#endif /* LAYER_FUNC_H */