summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--projects/openttd_vs80.vcproj4
-rw-r--r--projects/openttd_vs90.vcproj4
-rw-r--r--source.list1
-rw-r--r--src/station.cpp66
-rw-r--r--src/tilearea.cpp97
-rw-r--r--src/tilearea_type.h21
6 files changed, 110 insertions, 83 deletions
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index e15dedc1d..bb1b31a9e 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -720,6 +720,10 @@
>
</File>
<File
+ RelativePath=".\..\src\tilearea.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\townname.cpp"
>
</File>
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj
index eebb65465..eaaf5dd60 100644
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -717,6 +717,10 @@
>
</File>
<File
+ RelativePath=".\..\src\tilearea.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\townname.cpp"
>
</File>
diff --git a/source.list b/source.list
index 275341994..8829cff56 100644
--- a/source.list
+++ b/source.list
@@ -67,6 +67,7 @@ subsidy.cpp
texteff.cpp
tgp.cpp
tile_map.cpp
+tilearea.cpp
townname.cpp
#if WIN32
#else
diff --git a/src/station.cpp b/src/station.cpp
index e6b984d68..fef63b305 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -498,72 +498,6 @@ StationRect& StationRect::operator = (Rect src)
return *this;
}
-TileArea::TileArea(TileIndex start, TileIndex end)
-{
- uint sx = TileX(start);
- uint sy = TileY(start);
- uint ex = TileX(end);
- uint ey = TileY(end);
-
- if (sx > ex) Swap(sx, ex);
- if (sy > ey) Swap(sy, ey);
-
- this->tile = TileXY(sx, sy);
- this->w = ex - sx + 1;
- this->h = ey - sy + 1;
-}
-
-void TileArea::Add(TileIndex to_add)
-{
- if (this->tile == INVALID_TILE) {
- this->tile = to_add;
- this->w = 1;
- this->h = 1;
- return;
- }
-
- uint sx = TileX(this->tile);
- uint sy = TileY(this->tile);
- uint ex = sx + this->w - 1;
- uint ey = sy + this->h - 1;
-
- uint ax = TileX(to_add);
- uint ay = TileY(to_add);
-
- sx = min(ax, sx);
- sy = min(ay, sy);
- ex = max(ax, ex);
- ey = max(ay, ey);
-
- this->tile = TileXY(sx, sy);
- this->w = ex - sx + 1;
- this->h = ey - sy + 1;
-}
-
-bool TileArea::Intersects(const TileArea &ta) const
-{
- if (ta.w == 0 || this->w == 0) return false;
-
- assert(ta.w != 0 && ta.h != 0 && this->w != 0 && this->h != 0);
-
- uint left1 = TileX(this->tile);
- uint top1 = TileY(this->tile);
- uint right1 = left1 + this->w - 1;
- uint bottom1 = top1 + this->h - 1;
-
- uint left2 = TileX(ta.tile);
- uint top2 = TileY(ta.tile);
- uint right2 = left2 + ta.w - 1;
- uint bottom2 = top2 + ta.h - 1;
-
- return !(
- left2 > right1 ||
- right2 < left1 ||
- top2 > bottom1 ||
- bottom2 < top1
- );
-}
-
void InitializeStations()
{
diff --git a/src/tilearea.cpp b/src/tilearea.cpp
new file mode 100644
index 000000000..81efe96be
--- /dev/null
+++ b/src/tilearea.cpp
@@ -0,0 +1,97 @@
+/* $Id$ */
+
+/*
+ * This file is part of OpenTTD.
+ * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** @file tilearea.cpp Handling of tile areas. */
+
+#include "stdafx.h"
+
+#include "tile_map.h"
+#include "core/math_func.hpp"
+#include "tilearea_type.h"
+
+/**
+ * Construct this tile area based on two points.
+ * @param start the start of the area
+ * @param end the end of the area
+ */
+TileArea::TileArea(TileIndex start, TileIndex end)
+{
+ uint sx = TileX(start);
+ uint sy = TileY(start);
+ uint ex = TileX(end);
+ uint ey = TileY(end);
+
+ if (sx > ex) Swap(sx, ex);
+ if (sy > ey) Swap(sy, ey);
+
+ this->tile = TileXY(sx, sy);
+ this->w = ex - sx + 1;
+ this->h = ey - sy + 1;
+}
+
+/**
+ * Add a single tile to a tile area; enlarge if needed.
+ * @param to_add The tile to add
+ */
+void TileArea::Add(TileIndex to_add)
+{
+ if (this->tile == INVALID_TILE) {
+ this->tile = to_add;
+ this->w = 1;
+ this->h = 1;
+ return;
+ }
+
+ uint sx = TileX(this->tile);
+ uint sy = TileY(this->tile);
+ uint ex = sx + this->w - 1;
+ uint ey = sy + this->h - 1;
+
+ uint ax = TileX(to_add);
+ uint ay = TileY(to_add);
+
+ sx = min(ax, sx);
+ sy = min(ay, sy);
+ ex = max(ax, ex);
+ ey = max(ay, ey);
+
+ this->tile = TileXY(sx, sy);
+ this->w = ex - sx + 1;
+ this->h = ey - sy + 1;
+}
+
+/**
+ * Does this tile area intersect with another?
+ * @param ta the other tile area to check against.
+ * @return true if they intersect.
+ */
+bool TileArea::Intersects(const TileArea &ta) const
+{
+ if (ta.w == 0 || this->w == 0) return false;
+
+ assert(ta.w != 0 && ta.h != 0 && this->w != 0 && this->h != 0);
+
+ uint left1 = TileX(this->tile);
+ uint top1 = TileY(this->tile);
+ uint right1 = left1 + this->w - 1;
+ uint bottom1 = top1 + this->h - 1;
+
+ uint left2 = TileX(ta.tile);
+ uint top2 = TileY(ta.tile);
+ uint right2 = left2 + ta.w - 1;
+ uint bottom2 = top2 + ta.h - 1;
+
+ return !(
+ left2 > right1 ||
+ right2 < left1 ||
+ top2 > bottom1 ||
+ bottom2 < top1
+ );
+}
+
diff --git a/src/tilearea_type.h b/src/tilearea_type.h
index 6c2639cff..15045cb11 100644
--- a/src/tilearea_type.h
+++ b/src/tilearea_type.h
@@ -16,6 +16,10 @@
/** Represents the covered area of e.g. a rail station */
struct TileArea {
+ TileIndex tile; ///< The base tile of the area
+ uint8 w; ///< The width of the area
+ uint8 h; ///< The height of the area
+
/** Just construct this tile area */
TileArea() {}
@@ -27,21 +31,9 @@ struct TileArea {
*/
TileArea(TileIndex tile, uint8 w, uint8 h) : tile(tile), w(w), h(h) {}
- /**
- * Construct this tile area based on two points.
- * @param start the start of the area
- * @param end the end of the area
- */
TileArea(TileIndex start, TileIndex end);
- TileIndex tile; ///< The base tile of the area
- uint8 w; ///< The width of the area
- uint8 h; ///< The height of the area
- /**
- * Add a single tile to a tile area; enlarge if needed.
- * @param to_add The tile to add
- */
void Add(TileIndex to_add);
/**
@@ -54,11 +46,6 @@ struct TileArea {
this->h = 0;
}
- /**
- * Does this tile area intersect with another?
- * @param ta the other tile area to check against.
- * @return true if they intersect.
- */
bool Intersects(const TileArea &ta) const;
};