summaryrefslogtreecommitdiff
path: root/src/rail_cmd.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-03-19 20:50:19 +0000
committersmatz <smatz@openttd.org>2008-03-19 20:50:19 +0000
commit3ab59da68a4e360c502febc408986bc3de073954 (patch)
treee774ea23b6e94d9b81b383a3d13deff48bfd8762 /src/rail_cmd.cpp
parent606bc6fc14e41210d7bb8c45f973ef07d7b0a708 (diff)
downloadopenttd-3ab59da68a4e360c502febc408986bc3de073954.tar.xz
(svn r12386) -Fix [FS#1841](r2428): train could break apart when reversed while partially in a depot
Diffstat (limited to 'src/rail_cmd.cpp')
-rw-r--r--src/rail_cmd.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 118551c2e..724a7213d 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -2230,6 +2230,29 @@ static const signed char _deltacoord_leaveoffset[8] = {
0, 1, 0, -1 /* y */
};
+
+/** Compute number of ticks when next wagon will leave a depot.
+ * Negative means next wagon should have left depot n ticks before.
+ * @param v vehicle outside (leaving) the depot
+ * @return number of ticks when the next wagon will leave
+ */
+int TicksToLeaveDepot(const Vehicle *v)
+{
+ DiagDirection dir = GetRailDepotDirection(v->tile);
+ int length = v->u.rail.cached_veh_length;
+
+ switch (dir) {
+ case DIAGDIR_NE: return ((int)(v->x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) - (length + 1)));
+ case DIAGDIR_SE: return -((int)(v->y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4) + (length + 1)));
+ case DIAGDIR_SW: return -((int)(v->x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) + (length + 1)));
+ default:
+ case DIAGDIR_NW: return ((int)(v->y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4) - (length + 1)));
+ }
+
+ return 0; // make compilers happy
+}
+
+
static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y)
{
byte fract_coord;