summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2015-10-30 16:20:00 +0000
committerfrosch <frosch@openttd.org>2015-10-30 16:20:00 +0000
commit05ed2001d4749b0ad3d05948fe927576af4cdec4 (patch)
treec873df6234ea9f46df45d1e948f5b622cb40c911 /src
parent2c9117fbdd0d4b5e02a121e46f244a6cea501c40 (diff)
downloadopenttd-05ed2001d4749b0ad3d05948fe927576af4cdec4.tar.xz
(svn r27422) -Fix [FS#6341]: Aircraft picked the wrong airport entry point, if airports were rotated by 180 degree. (marcole)
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp2
-rw-r--r--src/direction_func.h20
2 files changed, 18 insertions, 4 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 18dcbea27..edb10af32 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -809,7 +809,7 @@ static byte AircraftGetEntryPoint(const Aircraft *v, const AirportFTAClass *apc,
/* We are northwest or southeast of the airport */
dir = delta_y < 0 ? DIAGDIR_NW : DIAGDIR_SE;
}
- dir = ChangeDiagDir(dir, (DiagDirDiff)ReverseDiagDir(DirToDiagDir(rotation)));
+ dir = ChangeDiagDir(dir, DiagDirDifference(DIAGDIR_NE, DirToDiagDir(rotation)));
return apc->entry_points[dir];
}
diff --git a/src/direction_func.h b/src/direction_func.h
index 888948584..12aee5863 100644
--- a/src/direction_func.h
+++ b/src/direction_func.h
@@ -61,11 +61,11 @@ static inline Direction ReverseDir(Direction d)
/**
- * Calculate the difference between to directions
+ * Calculate the difference between two directions
*
* @param d0 The first direction as the base
* @param d1 The second direction as the offset from the base
- * @return The difference how the second directions drifts of the first one.
+ * @return The difference how the second direction drifts of the first one.
*/
static inline DirDiff DirDifference(Direction d0, Direction d1)
{
@@ -79,7 +79,7 @@ static inline DirDiff DirDifference(Direction d0, Direction d1)
/**
* Applies two differences together
*
- * This function adds two differences together and return the resulting
+ * This function adds two differences together and returns the resulting
* difference. So adding two DIRDIFF_REVERSE together results in the
* DIRDIFF_SAME difference.
*
@@ -123,6 +123,20 @@ static inline DiagDirection ReverseDiagDir(DiagDirection d)
return (DiagDirection)(2 ^ d);
}
+/**
+ * Calculate the difference between two DiagDirection values
+ *
+ * @param d0 The first direction as the base
+ * @param d1 The second direction as the offset from the base
+ * @return The difference how the second direction drifts of the first one.
+ */
+static inline DiagDirDiff DiagDirDifference(DiagDirection d0, DiagDirection d1)
+{
+ assert(IsValidDiagDirection(d0));
+ assert(IsValidDiagDirection(d1));
+ /* Cast to uint so compiler can use bitmask. Result can never be negative. */
+ return (DiagDirDiff)((uint)(d0 - d1) % 4);
+}
/**
* Applies a difference on a DiagDirection