# HG changeset patch # User frosch # Date 2010-08-15 15:47:07 # Node ID b2ad31854a1f72b3efe11e6400d64b6daa559833 # Parent 0e843b449a0a2cfeadf41302442ffadca4fe2adb (svn r20500) -Fix: When converting rail all trains with a part on the converted rails need updating. Not only engines, which have power afterwards. Also update Acceleration after updating Power. diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -43,6 +43,9 @@ #include "table/railtypes.h" #include "table/track_land.h" +/** Helper type for lists/vectors of trains */ +typedef SmallVector TrainList; + RailtypeInfo _railtypes[RAILTYPE_END]; assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes)); @@ -1378,12 +1381,8 @@ static Vehicle *UpdateTrainPowerProc(Veh if (v->type != VEH_TRAIN) return NULL; /* Similar checks as in Train::PowerChanged() */ - - Train *t = Train::From(v); - if (t->IsArticulatedPart()) return NULL; - - const RailVehicleInfo *rvi = RailVehInfo(t->engine_type); - if (GetVehicleProperty(t, PROP_TRAIN_POWER, rvi->power) != 0) t->First()->PowerChanged(); + TrainList *affected_trains = static_cast(data); + affected_trains->Include(Train::From(v)->First()); return NULL; } @@ -1414,6 +1413,8 @@ CommandCost CmdConvertRail(TileIndex til if (ex < sx) Swap(ex, sx); if (ey < sy) Swap(ey, sy); + TrainList affected_trains; + CommandCost cost(EXPENSES_CONSTRUCTION); CommandCost error = CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK); // by default, there is no track to convert. for (uint x = sx; x <= ex; ++x) { @@ -1480,8 +1481,8 @@ CommandCost CmdConvertRail(TileIndex til SetRailType(tile, totype); MarkTileDirtyByTile(tile); - /* update power of train engines on this tile */ - FindVehicleOnPos(tile, NULL, &UpdateTrainPowerProc); + /* update power of train on this tile */ + FindVehicleOnPos(tile, &affected_trains, &UpdateTrainPowerProc); } } @@ -1543,8 +1544,8 @@ CommandCost CmdConvertRail(TileIndex til SetRailType(tile, totype); SetRailType(endtile, totype); - FindVehicleOnPos(tile, NULL, &UpdateTrainPowerProc); - FindVehicleOnPos(endtile, NULL, &UpdateTrainPowerProc); + FindVehicleOnPos(tile, &affected_trains, &UpdateTrainPowerProc); + FindVehicleOnPos(endtile, &affected_trains, &UpdateTrainPowerProc); YapfNotifyTrackLayoutChange(tile, track); YapfNotifyTrackLayoutChange(endtile, track); @@ -1579,6 +1580,14 @@ CommandCost CmdConvertRail(TileIndex til } } + if (flags & DC_EXEC) { + /* Railtype changed, update trains as when entering different track */ + for (Train **v = affected_trains.Begin(); v != affected_trains.End(); v++) { + (*v)->PowerChanged(); + (*v)->UpdateAcceleration(); + } + } + return (cost.GetCost() == 0) ? error : cost; }