Changeset - r8143:59f1aeab7b39
[Not reviewed]
master
0 1 0
smatz - 16 years ago 2007-12-27 13:25:23
smatz@openttd.org
(svn r11705) -Fix [FS#1557]: trains could have sprites with wrong direction when reversing, also was inconsistent with save/load process (possible desyncs)
1 file changed with 12 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/train_cmd.cpp
Show inline comments
 
@@ -1570,6 +1570,8 @@ static void AdvanceWagons(Vehicle *v, bo
 
			Vehicle *tempnext = last->Next();
 
			last->SetNext(NULL);
 

	
 
			/* do not update images now because the wagons are disconnected
 
			 * and that could cause problems with NewGRFs */
 
			for (int i = 0; i < differential; i++) TrainController(first, false);
 

	
 
			last->SetNext(tempnext);
 
@@ -1605,9 +1607,8 @@ static void ReverseTrainDirection(Vehicl
 
	}
 

	
 
	/* count number of vehicles */
 
	int r = -1;
 
	const Vehicle *u = v;
 
	do r++; while ((u = u->Next()) != NULL);
 
	int r = 0;  ///< number of vehicles - 1
 
	for (const Vehicle *u = v; (u = u->Next()) != NULL;) { r++; }
 

	
 
	AdvanceWagons(v, true);
 

	
 
@@ -1623,6 +1624,9 @@ static void ReverseTrainDirection(Vehicl
 
		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
	}
 

	
 
	/* update all images */
 
	for (Vehicle *u = v; u != NULL; u = u->Next()) { u->cur_image = u->GetImage(u->direction); }
 

	
 
	ClrBit(v->u.rail.flags, VRF_REVERSING);
 
}
 

	
 
@@ -2597,13 +2601,6 @@ static Direction GetNewVehicleDirectionB
 
	return _new_vehicle_direction_table[offs];
 
}
 

	
 
static Direction GetNewVehicleDirection(const Vehicle *v, int x, int y)
 
{
 
	uint offs = (y - v->y_pos + 1) * 4 + (x - v->x_pos + 1);
 
	assert(offs < 11);
 
	return _new_vehicle_direction_table[offs];
 
}
 

	
 
static int GetDirectionToVehicle(const Vehicle *v, int x, int y)
 
{
 
	byte offs;
 
@@ -2969,7 +2966,9 @@ static void TrainController(Vehicle *v, 
 
				v->direction = chosen_dir;
 
			}
 
		} else {
 
			/* In tunnel or on a bridge */
 
			/* In a tunnel or on a bridge
 
			 * - for tunnels, only the part when the vehicle is not visible (part of enter/exit tile too)
 
			 * - for bridges, only the middle part - without the bridge heads */
 
			if (!(v->vehstatus & VS_HIDDEN)) {
 
				v->cur_speed =
 
					min(v->cur_speed, GetBridge(GetBridgeType(v->tile))->speed);
 
@@ -2985,9 +2984,8 @@ static void TrainController(Vehicle *v, 
 
		}
 

	
 
		/* update image of train, as well as delta XY */
 
		Direction newdir = GetNewVehicleDirection(v, gp.x, gp.y);
 
		v->UpdateDeltaXY(newdir);
 
		if (update_image) v->cur_image = v->GetImage(newdir);
 
		v->UpdateDeltaXY(v->direction);
 
		if (update_image) v->cur_image = v->GetImage(v->direction);
 

	
 
		v->x_pos = gp.x;
 
		v->y_pos = gp.y;
0 comments (0 inline, 0 general)