28 uint sx =
TileX(start);
29 uint sy =
TileY(start);
33 if (sx > ex)
Swap(sx, ex);
34 if (sy > ey)
Swap(sy, ey);
37 this->
w = ex - sx + 1;
38 this->
h = ey - sy + 1;
56 uint ex = sx + this->
w - 1;
57 uint ey = sy + this->
h - 1;
59 uint ax =
TileX(to_add);
60 uint ay =
TileY(to_add);
68 this->w = ex - sx + 1;
69 this->h = ey - sy + 1;
79 if (ta.
w == 0 || this->w == 0)
return false;
81 assert(ta.
w != 0 && ta.
h != 0 && this->w != 0 && this->h != 0);
85 uint right1 = left1 + this->
w - 1;
86 uint bottom1 = top1 + this->
h - 1;
90 uint right2 = left2 + ta.
w - 1;
91 uint bottom2 = top2 + ta.
h - 1;
108 if (this->
w == 0)
return false;
110 assert(this->
w != 0 && this->
h != 0);
112 uint left =
TileX(this->tile);
113 uint top =
TileY(this->tile);
114 uint tile_x =
TileX(tile);
115 uint tile_y =
TileY(tile);
173 int start_a =
TileY(this->tile) +
TileX(this->tile);
174 int start_b =
TileY(this->tile) -
TileX(this->tile);
176 int end_a = start_a + this->
a;
177 int end_b = start_b + this->
b;
180 if (start_a > end_a) {
185 if (start_b > end_b) {
191 return (a >= start_a && a < end_a && b >= start_b && b < end_b);
202 bool new_line =
false;
205 if (this->a_max == 1 || this->a_max == -1) {
208 if (this->b_max > 0) {
209 this->b_cur =
min(this->b_cur + 2, this->b_max);
211 this->b_cur =
max(this->b_cur - 2, this->b_max);
215 if (this->a_max > 0) {
217 new_line = this->a_cur >= this->a_max;
220 new_line = this->a_cur <= this->a_max;
226 this->a_cur =
abs(this->a_cur) % 2 ? 0 : (this->a_max > 0 ? 1 : -1);
228 if (this->b_max > 0) {
237 uint x = this->base_x + (this->a_cur - this->b_cur) / 2;
238 uint y = this->base_y + (this->b_cur + this->a_cur) / 2;
241 }
while (this->
tile >
MapSize() && this->b_max != this->b_cur);
TileIndex tile
Base tile of the area.
static void Swap(T &a, T &b)
Type safe swap operation.
void ClampToMap()
Clamp the tile area to map borders.
static uint MapSizeX()
Get the size of the map along the X.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
DiagonalTileArea(TileIndex tile=INVALID_TILE, int8 a=0, int8 b=0)
Construct this tile area with some set values.
static uint MapSizeY()
Get the size of the map along the Y.
static uint TileX(TileIndex tile)
Get the X component of a tile.
static bool IsInsideBS(const T x, const uint base, const uint size)
Checks if a value is between a window started at some base point.
int16 a
Extent in diagonal "x" direction (may be negative to signify the area stretches to the left) ...
static T max(const T a, const T b)
Returns the maximum of two values.
uint16 w
The width of the area.
OrthogonalTileArea(TileIndex tile=INVALID_TILE, uint8 w=0, uint8 h=0)
Construct this tile area with some set values.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
bool Intersects(const OrthogonalTileArea &ta) const
Does this tile area intersect with another?
int16 b
Extent in diagonal "y" direction (may be negative to signify the area stretches upwards) ...
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
Represents the covered area of e.g.
Base class for tile iterators.
static T min(const T a, const T b)
Returns the minimum of two values.
TileIterator & operator++()
Move ourselves to the next tile in the rectangle on the map.
TileIndex tile
The base tile of the area.
static uint MapSize()
Get the size of the map.
uint32 TileIndex
The index/ID of a Tile.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Type for storing the 'area' of something uses on the map.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
uint16 h
The height of the area.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?