diff options
author | michi_cc <michi_cc@openttd.org> | 2011-11-21 20:51:43 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2011-11-21 20:51:43 +0000 |
commit | 4d2a9e384ccb83eec9992ad36459f495bfcfe60f (patch) | |
tree | 26d51a4b166e5dfeff2c1e2bbe753b73df80332b /src/train.h | |
parent | 3748cab60876e98e530c514307e303a071498461 (diff) | |
download | openttd-4d2a9e384ccb83eec9992ad36459f495bfcfe60f.tar.xz |
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
Diffstat (limited to 'src/train.h')
-rw-r--r-- | src/train.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/train.h b/src/train.h index ad273e035..9bc40fe97 100644 --- a/src/train.h +++ b/src/train.h @@ -148,6 +148,18 @@ struct Train : public GroundVehicle<Train, VEH_TRAIN> { return v; } + /** + * Calculate the offset from this vehicle's center to the following center taking the vehicle lengths into account. + * @return Offset from center to center. + */ + int CalcNextVehicleOffset() const + { + /* For vehicles with odd lengths the part before the center will be one unit + * longer than the part after the center. This means we have to round up the + * length of the next vehicle but may not round the length of the current + * vehicle. */ + return this->gcache.cached_veh_length / 2 + (this->Next() != NULL ? this->Next()->gcache.cached_veh_length + 1 : 0) / 2; + } protected: // These functions should not be called outside acceleration code. |