summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-03-08 07:48:56 +0000
committertron <tron@openttd.org>2006-03-08 07:48:56 +0000
commitecabf8a5f0b39626efef5c720f302a3169c8cdab (patch)
treef7e5f43e03b4cc5ea6f80ee95a7e5827601efcbf /vehicle.c
parentfbe939b31f8c7ea4e6e47d6d903625dd25c5e856 (diff)
downloadopenttd-ecabf8a5f0b39626efef5c720f302a3169c8cdab.tar.xz
(svn r3784) Add a type and functions to handle direction changes
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/vehicle.c b/vehicle.c
index e4dd53774..24d7b731f 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1930,7 +1930,7 @@ static const Direction _new_direction_table[] = {
Direction GetDirectionTowards(const Vehicle* v, int x, int y)
{
Direction dir;
- byte dirdiff;
+ DirDiff dirdiff;
int i = 0;
if (y >= v->y_pos) {
@@ -1945,10 +1945,9 @@ Direction GetDirectionTowards(const Vehicle* v, int x, int y)
dir = v->direction;
- dirdiff = _new_direction_table[i] - dir;
- if (dirdiff == 0)
- return dir;
- return (dir+((dirdiff&7)<5?1:-1)) & 7;
+ dirdiff = DirDifference(_new_direction_table[i], dir);
+ if (dirdiff == DIRDIFF_SAME) return dir;
+ return ChangeDir(dir, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT);
}
Trackdir GetVehicleTrackdir(const Vehicle* v)