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
 
@@ -40,12 +40,15 @@
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
#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));
 

	
 
/**
 
 * Initialize rail type information.
 
@@ -1375,18 +1378,14 @@ CommandCost CmdRemoveSignalTrack(TileInd
 
/** Update power of train under which is the railtype being converted */
 
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;
 
}
 

	
 
/**
 
 * Convert one rail type to the other. You can convert normal rail to
 
@@ -1411,12 +1410,14 @@ CommandCost CmdConvertRail(TileIndex til
 
	uint sy = TileY(p1);
 

	
 
	/* make sure sx,sy are smaller than ex,ey */
 
	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) {
 
		for (uint y = sy; y <= ey; ++y) {
 
			TileIndex tile = TileXY(x, y);
 
			TileType tt = GetTileType(tile);
 
@@ -1477,14 +1478,14 @@ CommandCost CmdConvertRail(TileIndex til
 
							*vehicles_affected.Append() = v;
 
						}
 
					}
 

	
 
					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);
 
				}
 
			}
 

	
 
			switch (tt) {
 
				case MP_RAILWAY:
 
					switch (GetRailTileType(tile)) {
 
@@ -1540,14 +1541,14 @@ CommandCost CmdConvertRail(TileIndex til
 
								*vehicles_affected.Append() = v;
 
							}
 
						}
 
						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);
 

	
 
						MarkTileDirtyByTile(tile);
 
						MarkTileDirtyByTile(endtile);
 
@@ -1576,12 +1577,20 @@ CommandCost CmdConvertRail(TileIndex til
 
			for (uint i = 0; i < vehicles_affected.Length(); ++i) {
 
				TryPathReserve(vehicles_affected[i], true);
 
			}
 
		}
 
	}
 

	
 
	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;
 
}
 

	
 
static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (_current_company != OWNER_WATER) {
0 comments (0 inline, 0 general)