summaryrefslogtreecommitdiff
path: root/train_cmd.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
commit9273d0d2b9a09fd0d5f5e59ebb38d40fbdbf18a8 (patch)
treef7e5f43e03b4cc5ea6f80ee95a7e5827601efcbf /train_cmd.c
parent8cfcdaa733684b00500f7811087312e6d8e60bc0 (diff)
downloadopenttd-9273d0d2b9a09fd0d5f5e59ebb38d40fbdbf18a8.tar.xz
(svn r3784) Add a type and functions to handle direction changes
Diffstat (limited to 'train_cmd.c')
-rw-r--r--train_cmd.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/train_cmd.c b/train_cmd.c
index 49c186e8f..960af695a 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -2591,14 +2591,16 @@ static const RailtypeSlowdownParams _railtype_slowdown[3] = {
/* Modify the speed of the vehicle due to a turn */
static void AffectSpeedByDirChange(Vehicle* v, Direction new_dir)
{
- byte diff;
+ DirDiff diff;
const RailtypeSlowdownParams *rsp;
- if (_patches.realistic_acceleration || (diff = (v->direction - new_dir) & 7) == 0)
- return;
+ if (_patches.realistic_acceleration) return;
+
+ diff = DirDifference(v->direction, new_dir);
+ if (diff == DIRDIFF_SAME) return;
rsp = &_railtype_slowdown[v->u.rail.railtype];
- v->cur_speed -= ((diff == 1 || diff == 7) ? rsp->small_turn : rsp->large_turn) * v->cur_speed >> 8;
+ v->cur_speed -= (diff == DIRDIFF_45RIGHT || diff == DIRDIFF_45LEFT ? rsp->small_turn : rsp->large_turn) * v->cur_speed >> 8;
}
/* Modify the speed of the vehicle due to a change in altitude */
@@ -2739,11 +2741,10 @@ static void *CheckVehicleAtSignal(Vehicle *v, void *data)
{
const VehicleAtSignalData* vasd = data;
- if (v->type == VEH_Train && IsFrontEngine(v) &&
- v->tile == vasd->tile) {
- byte diff = (v->direction - vasd->direction + 2) & 7;
+ if (v->type == VEH_Train && IsFrontEngine(v) && v->tile == vasd->tile) {
+ DirDiff diff = ChangeDirDiff(DirDifference(v->direction, vasd->direction), DIRDIFF_90RIGHT);
- if (diff == 2 || (v->cur_speed <= 5 && diff <= 4)) return v;
+ if (diff == DIRDIFF_90RIGHT || (v->cur_speed <= 5 && diff <= DIRDIFF_REVERSE)) return v;
}
return NULL;
}