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 22 insertions and 12 deletions:
0 comments (0 inline, 0 general)
train_cmd.c
Show inline comments
 
@@ -959,54 +959,61 @@ static void ReverseTrainSwapVeh(Vehicle 
 
	}
 
}
 

	
 
/* Check if the vehicle is a train and is on the tile we are testing */
 
static void *TestTrainOnCrossing(Vehicle *v, void *data)
 
{
 
	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))
 
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 

	
 
	/* Check if we were approaching a rail/road-crossing */
 
	{
 
		TileIndex tile = v->tile;
 
		int t;
 
		/* Determine the non-diagonal direction in which we will exit this tile */
 
		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 );
 

	
 
	/* swap start<>end, start+1<>end-1, ... */
 
	do {
 
		ReverseTrainSwapVeh(v, l++, r--);
 
	} while (l <= r);
 

	
 
	if (IsTrainDepotTile(v->tile))
 
@@ -2319,24 +2326,27 @@ static void DeleteLastWagon(Vehicle *v)
 
	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
 
	RebuildVehicleLists();
 
	InvalidateWindow(WC_COMPANY, v->owner);
 

	
 
	BeginVehicleMove(v);
 
	EndVehicleMove(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);
 
		if ((v->direction == 3) || (v->direction == 7) )
 
			SetSignalsOnBothDir(v->tile,1);
 
			SetSignalsOnBothDir(endtile,1);
 
	}
 
}
 

	
 
@@ -2380,25 +2390,25 @@ static void HandleCrashedTrain(Vehicle *
 
					2 + ((r>>16)&7),
 
					5 + (r&7),
 
					EV_DEMOLISH);
 
				break;
 
			}
 
		} while ( (u=u->next) != NULL);
 
	}
 

	
 
	if (state <= 240 && !(v->tick_counter&3)) {
 
		ChangeTrainDirRandomly(v);
 
	}
 

	
 
	if (state >= 4440 && !(v->tick_counter&0x1F))
 
	if (state >= 4440 && !(v->tick_counter&0x1F))		
 
		DeleteLastWagon(v);
 
}
 

	
 
static void HandleBrokenTrain(Vehicle *v)
 
{
 
	if (v->breakdown_ctr != 1) {
 
		v->breakdown_ctr = 1;
 
		v->cur_speed = 0;
 

	
 
		if (v->breakdowns_since_last_service != 255)
 
			v->breakdowns_since_last_service++;
 

	
0 comments (0 inline, 0 general)