Changeset - r15811:b2ad31854a1f
[Not reviewed]
master
0 1 0
frosch - 14 years ago 2010-08-15 15:47:07
frosch@openttd.org
(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.
1 file changed with 19 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -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(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<TrainList*>(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;
 
}
 

	
0 comments (0 inline, 0 general)