mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(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.
This commit is contained in:
parent
35fec79700
commit
a0520bb8bf
@ -43,6 +43,9 @@
|
||||
#include "table/railtypes.h"
|
||||
#include "table/track_land.h"
|
||||
|
||||
/** Helper type for lists/vectors of trains */
|
||||
typedef SmallVector<Train *, 16> TrainList;
|
||||
|
||||
RailtypeInfo _railtypes[RAILTYPE_END];
|
||||
|
||||
assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes));
|
||||
@ -1378,12 +1381,8 @@ static Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
|
||||
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<TrainList*>(data);
|
||||
affected_trains->Include(Train::From(v)->First());
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -1414,6 +1413,8 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||
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 tile, DoCommandFlag flags, uint32 p1, uint3
|
||||
|
||||
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 tile, DoCommandFlag flags, uint32 p1, uint3
|
||||
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 tile, DoCommandFlag flags, uint32 p1, uint3
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user