src/roadveh_cmd.cpp
changeset 7416 cced8adef086
parent 7398 b933416cf32b
child 7418 ef667c8ccda0
equal deleted inserted replaced
7415:236b512fd8a1 7416:cced8adef086
  1374 	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
  1374 	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
  1375 
  1375 
  1376 	return true;
  1376 	return true;
  1377 }
  1377 }
  1378 
  1378 
  1379 static Trackdir FollowPreviousRoadVehicle(const Vehicle *v, const Vehicle *prev, TileIndex tile, DiagDirection entry_dir)
  1379 static Trackdir FollowPreviousRoadVehicle(const Vehicle *v, const Vehicle *prev, TileIndex tile, DiagDirection entry_dir, bool already_reversed)
  1380 {
  1380 {
  1381 	if (prev->tile == v->tile) {
  1381 	if (prev->tile == v->tile && !already_reversed) {
  1382 		/* If the previous vehicle is on the same tile as this vehicle is
  1382 		/* If the previous vehicle is on the same tile as this vehicle is
  1383 		 * then it must have reversed. */
  1383 		 * then it must have reversed. */
  1384 		return _road_reverse_table[entry_dir];
  1384 		return _road_reverse_table[entry_dir];
  1385 	}
  1385 	}
  1386 
  1386 
  1489 
  1489 
  1490 		if (IsRoadVehFront(v)) {
  1490 		if (IsRoadVehFront(v)) {
  1491 			/* If this is the front engine, look for the right path. */
  1491 			/* If this is the front engine, look for the right path. */
  1492 			dir = RoadFindPathToDest(v, tile, (DiagDirection)(rd.x & 3));
  1492 			dir = RoadFindPathToDest(v, tile, (DiagDirection)(rd.x & 3));
  1493 		} else {
  1493 		} else {
  1494 			dir = FollowPreviousRoadVehicle(v, prev, tile, (DiagDirection)(rd.x & 3));
  1494 			dir = FollowPreviousRoadVehicle(v, prev, tile, (DiagDirection)(rd.x & 3), false);
  1495 		}
  1495 		}
  1496 
  1496 
  1497 		if (dir == INVALID_TRACKDIR) {
  1497 		if (dir == INVALID_TRACKDIR) {
  1498 			if (!IsRoadVehFront(v)) error("!Disconnecting road vehicle.");
  1498 			if (!IsRoadVehFront(v)) error("!Disconnecting road vehicle.");
  1499 			v->cur_speed = 0;
  1499 			v->cur_speed = 0;
  1581 		return true;
  1581 		return true;
  1582 	}
  1582 	}
  1583 
  1583 
  1584 	if (rd.x & RDE_TURNED) {
  1584 	if (rd.x & RDE_TURNED) {
  1585 		/* Vehicle has finished turning around, it will now head back onto the same tile */
  1585 		/* Vehicle has finished turning around, it will now head back onto the same tile */
  1586 		Trackdir dir = RoadFindPathToDest(v, v->tile, (DiagDirection)(rd.x & 3));
  1586 		Trackdir dir;
  1587 		uint32 r;
  1587 		uint32 r;
  1588 		Direction newdir;
  1588 		Direction newdir;
  1589 		const RoadDriveEntry *rdp;
  1589 		const RoadDriveEntry *rdp;
       
  1590 
       
  1591 		if (IsRoadVehFront(v)) {
       
  1592 			/* If this is the front engine, look for the right path. */
       
  1593 			dir = RoadFindPathToDest(v, v->tile, (DiagDirection)(rd.x & 3));
       
  1594 		} else {
       
  1595 			dir = FollowPreviousRoadVehicle(v, prev, v->tile, (DiagDirection)(rd.x & 3), true);
       
  1596 		}
  1590 
  1597 
  1591 		if (dir == INVALID_TRACKDIR) {
  1598 		if (dir == INVALID_TRACKDIR) {
  1592 			v->cur_speed = 0;
  1599 			v->cur_speed = 0;
  1593 			return false;
  1600 			return false;
  1594 		}
  1601 		}