summaryrefslogtreecommitdiff
path: root/train_cmd.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2005-11-07 23:20:47 +0000
committerbjarni <bjarni@openttd.org>2005-11-07 23:20:47 +0000
commit5481dcd191a1b763330345d11264de6eac91a106 (patch)
tree419d4e9a7f19cca429bc209799068506c9d20f9d /train_cmd.c
parent723e789b2f1ac1d6f8eaa122d9626f41595c51cf (diff)
downloadopenttd-5481dcd191a1b763330345d11264de6eac91a106.tar.xz
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
-Trains will now remember the length of stations it visits and sell cars when being autoreplaced if they became too long -If it needs to remove cars, then it starts from the front and sells all it can find until the train is short enough -This only works for trains, that knows the station length of the route so a full uninterrupted run is needed -a train needs 1-2 runs to detect if the shortest station is expanded -This feature can be turned on and off in the train replace window and each company can have it's own setting -NOTE: minor savegame version bump
Diffstat (limited to 'train_cmd.c')
-rw-r--r--train_cmd.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/train_cmd.c b/train_cmd.c
index 0e79e76a0..e5daaf014 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -752,6 +752,9 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->type = VEH_Train;
v->cur_image = 0xAC2;
+ v->u.rail.shortest_platform[0] = 255;
+ v->u.rail.shortest_platform[1] = 0;
+
VehiclePositionChanged(v);
if (rvi->flags & RVI_MULTIHEAD && !HASBIT(p2, 0)) {
@@ -2349,6 +2352,27 @@ static bool ProcessTrainOrder(Vehicle *v)
v->dest_tile = 0;
+ // store the station length if no shorter station was visited this order round
+ if (v->cur_order_index == 0) {
+ if (v->u.rail.shortest_platform[1] != 0 && v->u.rail.shortest_platform[1] != 255) {
+ // we went though a whole round of orders without interruptions, so we store the length of the shortest station
+ v->u.rail.shortest_platform[0] = v->u.rail.shortest_platform[1];
+ }
+ // all platforms are shorter than 255, so now we can find the shortest in the next order round. They might have changed size
+ v->u.rail.shortest_platform[1] = 255;
+ }
+
+ if (v->last_station_visited != INVALID_STATION) {
+ Station *st = GetStation(v->last_station_visited);
+ if (TileBelongsToRailStation(st, v->tile)) {
+ byte length = GetStationPlatforms(st, v->tile);
+
+ if (length < v->u.rail.shortest_platform[1]) {
+ v->u.rail.shortest_platform[1] = length;
+ }
+ }
+ }
+
result = false;
switch (order->type) {
case OT_GOTO_STATION: