10#ifndef TILEAREA_TYPE_H
11#define TILEAREA_TYPE_H
61 return TileAddXY(this->tile, this->w / 2, this->h / 2);
146 virtual std::unique_ptr<TileIterator>
Clone()
const = 0;
153 return this->tile == rhs.
tile;
160 return this->tile != rhs.
tile;
168 return this->tile == rhs;
175 return this->tile != rhs;
216 }
else if (--this->y > 0) {
225 std::unique_ptr<TileIterator>
Clone()
const override
227 return std::make_unique<OrthogonalTileIterator>(*
this);
264 std::unique_ptr<TileIterator>
Clone()
const override
266 return std::make_unique<DiagonalTileIterator>(*
this);
Iterator to iterate over a diagonal area of the map.
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
DiagonalTileIterator(const DiagonalTileArea &ta)
Construct the iterator.
uint base_x
The base tile x coordinate from where the iterating happens.
int a_max
The (rotated) x coordinate of the end of the iteration.
DiagonalTileIterator(TileIndex corner1, TileIndex corner2)
Construct the iterator.
int b_max
The (rotated) y coordinate of the end of the iteration.
int b_cur
The current (rotated) y coordinate of the iteration.
int a_cur
The current (rotated) x coordinate of the iteration.
std::unique_ptr< TileIterator > Clone() const override
Allocate a new iterator that is a copy of this one.
uint base_y
The base tile y coordinate from where the iterating happens.
Iterator to iterate over a tile area (rectangle) of the map.
OrthogonalTileIterator(TileIndex corner1, TileIndex corner2)
Construct the iterator.
OrthogonalTileIterator(const OrthogonalTileArea &ta)
Construct the iterator.
int y
The current 'y' position in the rectangle.
int w
The width of the iterated area.
int x
The current 'x' position in the rectangle.
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
std::unique_ptr< TileIterator > Clone() const override
Allocate a new iterator that is a copy of this one.
Base class for tile iterators.
TileIndex operator*() const
Get the tile we are currently at.
TileIterator(TileIndex tile=INVALID_TILE)
Initialise the iterator starting at this tile.
virtual std::unique_ptr< TileIterator > Clone() const =0
Allocate a new iterator that is a copy of this one.
TileIndex tile
The current tile we are at.
bool operator==(const TileIterator &rhs) const
Equality comparison.
bool operator!=(const TileIterator &rhs) const
Inequality comparison.
virtual TileIterator & operator++()=0
Move ourselves to the next tile in the rectangle on the map.
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
Functions related to maps.
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Represents a diagonal tile area.
void Clear()
Clears the TileArea by making the tile invalid and setting a and b to 0.
int16_t b
Extent in diagonal "y" direction (may be negative to signify the area stretches upwards)
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
int16_t a
Extent in diagonal "x" direction (may be negative to signify the area stretches to the left)
TileIndex tile
Base tile of the area.
DiagonalTileArea(TileIndex tile=INVALID_TILE, int16_t a=0, int16_t b=0)
Construct this tile area with some set values.
Represents the covered area of e.g.
OrthogonalTileIterator end() const
Returns an iterator to the end of the tile area.
void ClampToMap()
Clamp the tile area to map borders.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
uint16_t w
The width of the area.
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?
TileIndex GetCenterTile() const
Get the center tile.
void Clear()
Clears the 'tile area', i.e.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
OrthogonalTileIterator begin() const
Returns an iterator to the beginning of the tile area.
OrthogonalTileArea(TileIndex tile=INVALID_TILE, uint16_t w=0, uint16_t h=0)
Construct this tile area with some set values.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.