Changeset - r23320:97156f91292d
[Not reviewed]
master
0 1 0
Joan Josep - 6 years ago 2019-02-16 20:52:49
juanjo.ng.83@gmail.com
Codechange: Re-arrange VehicleEnter_Track in rail_cmd. (#7239)
1 file changed with 21 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -2912,14 +2912,21 @@ int TicksToLeaveDepot(const Train *v)
 
 */
 
static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int x, int y)
 
{
 
	/* this routine applies only to trains in depot tiles */
 
	/* This routine applies only to trains in depot tiles. */
 
	if (u->type != VEH_TRAIN || !IsRailDepotTile(tile)) return VETSB_CONTINUE;
 

	
 
	/* Depot direction. */
 
	DiagDirection dir = GetRailDepotDirection(tile);
 

	
 
	byte fract_coord = (x & 0xF) + ((y & 0xF) << 4);
 

	
 
	/* Make sure a train is not entering the tile from behind. */
 
	if (_fractcoords_behind[dir] == fract_coord) return VETSB_CANNOT_ENTER;
 

	
 
	Train *v = Train::From(u);
 

	
 
	/* depot direction */
 
	DiagDirection dir = GetRailDepotDirection(tile);
 

	
 
	/* Leaving depot? */
 
	if (v->direction == DiagDirToDir(dir)) {
 
	/* Calculate the point where the following wagon should be activated. */
 
	int length = v->CalcNextVehicleOffset();
 

	
 
@@ -2929,16 +2936,18 @@ static VehicleEnterTileStatus VehicleEnt
 
		(((_fractcoords_enter[dir] >> 4) +  // y
 
			((length + 1) * _deltacoord_leaveoffset[dir + 4])) << 4);
 

	
 
	byte fract_coord = (x & 0xF) + ((y & 0xF) << 4);
 

	
 
	if (_fractcoords_behind[dir] == fract_coord) {
 
		/* make sure a train is not entering the tile from behind */
 
		return VETSB_CANNOT_ENTER;
 
		if (fract_coord_leave == fract_coord) {
 
			/* Leave the depot. */
 
			if ((v = v->Next()) != NULL) {
 
				v->vehstatus &= ~VS_HIDDEN;
 
				v->track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
 
			}
 
		}
 
	} else if (_fractcoords_enter[dir] == fract_coord) {
 
		if (DiagDirToDir(ReverseDiagDir(dir)) == v->direction) {
 
			/* enter the depot */
 
		/* Entering depot. */
 
		assert(DiagDirToDir(ReverseDiagDir(dir)) == v->direction);
 
			v->track = TRACK_BIT_DEPOT,
 
			v->vehstatus |= VS_HIDDEN; // hide it
 
		v->vehstatus |= VS_HIDDEN;
 
			v->direction = ReverseDir(v->direction);
 
			if (v->Next() == NULL) VehicleEnterDepot(v->First());
 
			v->tile = tile;
 
@@ -2946,15 +2955,6 @@ static VehicleEnterTileStatus VehicleEnt
 
			InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
			return VETSB_ENTERED_WORMHOLE;
 
		}
 
	} else if (fract_coord_leave == fract_coord) {
 
		if (DiagDirToDir(dir) == v->direction) {
 
			/* leave the depot? */
 
			if ((v = v->Next()) != NULL) {
 
				v->vehstatus &= ~VS_HIDDEN;
 
				v->track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
 
			}
 
		}
 
	}
 

	
 
	return VETSB_CONTINUE;
 
}
0 comments (0 inline, 0 general)