Changeset - r1103:42851444e1e3
[Not reviewed]
master
0 1 0
dominik - 20 years ago 2005-01-23 10:40:54
dominik@openttd.org
(svn r1604) Fix: [ 1105112 ] Destroyed train locks crossings
1 file changed with 21 insertions and 11 deletions:
0 comments (0 inline, 0 general)
train_cmd.c
Show inline comments
 
@@ -965,12 +965,27 @@ static void *TestTrainOnCrossing(Vehicle
 
	if (v->tile != *(const TileIndex*)data || v->type != VEH_Train)
 
		return NULL;
 

	
 
	return v;
 
}
 

	
 
static void DisableTrainCrossing(TileIndex tile)
 
{
 
	/* Test if we have a rail/road-crossing */
 
	if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
 
		/* Check if there is a train on the tile itself */
 
		if (VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL) {
 
			/* If light is on, switch light off */
 
			if (_map5[tile] & 4) {
 
				_map5[tile] &= ~4;
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
	}
 
}
 

	
 
static void ReverseTrainDirection(Vehicle *v)
 
{
 
	int l = 0, r = -1;
 
	Vehicle *u;
 

	
 
	if (IsTrainDepotTile(v->tile))
 
@@ -984,23 +999,15 @@ static void ReverseTrainDirection(Vehicl
 
		t = v->direction >> 1;
 
		if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[t]) {
 
			t = (t - 1) & 3;
 
		}
 
		/* Calculate next tile */
 
		tile += TileOffsByDir(t);
 
		/* Test if we have a rail/road-crossing */
 
		if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
 
			/* Check if there is a train on the tile itself */
 
			if (VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL) {
 
				/* If light is on, switch light off */
 
				if (_map5[tile] & 4) {
 
					_map5[tile] &= ~4;
 
					MarkTileDirtyByTile(tile);
 
				}
 
			}
 
		}
 

	
 
		/* Check if the train left a rail/road-crossing */
 
		DisableTrainCrossing(tile);
 
	}
 

	
 
	// count number of vehicles
 
	u = v;
 
	do r++; while ( (u = u->next) != NULL );
 

	
 
@@ -2325,12 +2332,15 @@ static void DeleteLastWagon(Vehicle *v)
 
	DeleteVehicle(v);
 

	
 
	if (!((t=v->u.rail.track) & 0xC0)) {
 
		SetSignalsOnBothDir(v->tile, FIND_FIRST_BIT(t));
 
	}
 

	
 
	/* Check if the wagon was on a road/rail-crossing and disable it if no others are on it */
 
	DisableTrainCrossing(v->tile);
 

	
 
	if (v->u.rail.track == 0x40) {
 
		int length;
 
		TileIndex endtile = CheckTunnelBusy(v->tile, &length);
 
		if ((v->direction == 1) || (v->direction == 5) )
 
			SetSignalsOnBothDir(v->tile,0);
 
			SetSignalsOnBothDir(endtile,0);
0 comments (0 inline, 0 general)