Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef TILEAREA_TYPE_H
00013 #define TILEAREA_TYPE_H
00014
00015 #include "map_func.h"
00016
00018 struct TileArea {
00019 TileIndex tile;
00020 uint16 w;
00021 uint16 h;
00022
00024 TileArea() {}
00025
00032 TileArea(TileIndex tile, uint8 w, uint8 h) : tile(tile), w(w), h(h) {}
00033
00034 TileArea(TileIndex start, TileIndex end);
00035
00036
00037 void Add(TileIndex to_add);
00038
00042 void Clear()
00043 {
00044 this->tile = INVALID_TILE;
00045 this->w = 0;
00046 this->h = 0;
00047 }
00048
00049 bool Intersects(const TileArea &ta) const;
00050
00051 bool Contains(TileIndex tile) const;
00052
00053 void ClampToMap();
00054
00059 TileIndex GetCenterTile() const
00060 {
00061 return TILE_ADDXY(this->tile, this->w / 2, this->h / 2);
00062 }
00063 };
00064
00066 class TileIterator {
00067 protected:
00068 TileIndex tile;
00069
00074 TileIterator(TileIndex tile) : tile(tile)
00075 {
00076 }
00077
00078 public:
00080 virtual ~TileIterator()
00081 {
00082 }
00083
00088 FORCEINLINE operator TileIndex () const
00089 {
00090 return this->tile;
00091 }
00092
00096 virtual TileIterator& operator ++() = 0;
00097 };
00098
00100 class OrthogonalTileIterator : public TileIterator {
00101 private:
00102 int w;
00103 int x;
00104 int y;
00105
00106 public:
00111 OrthogonalTileIterator(const TileArea &ta) : TileIterator(ta.w == 0 || ta.h == 0 ? INVALID_TILE : ta.tile), w(ta.w), x(ta.w), y(ta.h)
00112 {
00113 }
00114
00118 FORCEINLINE TileIterator& operator ++()
00119 {
00120 assert(this->tile != INVALID_TILE);
00121
00122 if (--this->x > 0) {
00123 this->tile++;
00124 } else if (--this->y > 0) {
00125 this->x = this->w;
00126 this->tile += TileDiffXY(1, 1) - this->w;
00127 } else {
00128 this->tile = INVALID_TILE;
00129 }
00130 return *this;
00131 }
00132 };
00133
00135 class DiagonalTileIterator : public TileIterator {
00136 private:
00137 uint base_x;
00138 uint base_y;
00139 int a_cur;
00140 int b_cur;
00141 int a_max;
00142 int b_max;
00143
00144 public:
00145 DiagonalTileIterator(TileIndex begin, TileIndex end);
00146
00147 TileIterator& operator ++();
00148 };
00149
00156 #define TILE_AREA_LOOP(var, ta) for (OrthogonalTileIterator var(ta); var != INVALID_TILE; ++var)
00157
00158 #endif