equal
deleted
inserted
replaced
827 } |
827 } |
828 |
828 |
829 |
829 |
830 /* Check if all the wagons of the given train are in a depot, returns the |
830 /* Check if all the wagons of the given train are in a depot, returns the |
831 * number of cars (including loco) then. If not it returns -1 */ |
831 * number of cars (including loco) then. If not it returns -1 */ |
832 int CheckTrainStoppedInDepot(const Vehicle *v) |
832 static int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped) |
833 { |
833 { |
834 int count; |
834 int count; |
835 TileIndex tile = v->tile; |
835 TileIndex tile = v->tile; |
836 |
836 |
837 /* check if stopped in a depot */ |
837 /* check if stopped in a depot */ |
844 * engines with more articulated parts than before works correctly. |
844 * engines with more articulated parts than before works correctly. |
845 * |
845 * |
846 * Also skip counting rear ends of multiheaded engines */ |
846 * Also skip counting rear ends of multiheaded engines */ |
847 if (!IsArticulatedPart(v) && !(!IsTrainEngine(v) && IsMultiheaded(v))) count++; |
847 if (!IsArticulatedPart(v) && !(!IsTrainEngine(v) && IsMultiheaded(v))) count++; |
848 if (v->u.rail.track != 0x80 || v->tile != tile || |
848 if (v->u.rail.track != 0x80 || v->tile != tile || |
849 (IsFrontEngine(v) && !(v->vehstatus & VS_STOPPED))) { |
849 (IsFrontEngine(v) && needs_to_be_stopped && !(v->vehstatus & VS_STOPPED))) { |
850 return -1; |
850 return -1; |
851 } |
851 } |
852 } |
852 } |
853 |
853 |
854 return count; |
854 return count; |
|
855 } |
|
856 |
|
857 /* Used to check if the train is inside the depot and verifying that the VS_STOPPED flag is set */ |
|
858 inline int CheckTrainStoppedInDepot(const Vehicle *v) |
|
859 { |
|
860 return CheckTrainInDepot(v, true); |
|
861 } |
|
862 |
|
863 /* Used to check if the train is inside the depot, but not checking the VS_STOPPED flag */ |
|
864 inline bool CheckTrainIsInsideDepot(const Vehicle *v) |
|
865 { |
|
866 return (CheckTrainInDepot(v, false) > 0); |
855 } |
867 } |
856 |
868 |
857 /** |
869 /** |
858 * Unlink a rail wagon from the consist. |
870 * Unlink a rail wagon from the consist. |
859 * @param v Vehicle to remove. |
871 * @param v Vehicle to remove. |
3509 // depot visit by the order list. |
3521 // depot visit by the order list. |
3510 if (v->current_order.type == OT_GOTO_DEPOT && |
3522 if (v->current_order.type == OT_GOTO_DEPOT && |
3511 (v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0) |
3523 (v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0) |
3512 return; |
3524 return; |
3513 |
3525 |
|
3526 if (CheckTrainIsInsideDepot(v)) { |
|
3527 VehicleServiceInDepot(v); |
|
3528 return; |
|
3529 } |
|
3530 |
3514 tfdd = FindClosestTrainDepot(v, MAX_ACCEPTABLE_DEPOT_DIST); |
3531 tfdd = FindClosestTrainDepot(v, MAX_ACCEPTABLE_DEPOT_DIST); |
3515 /* Only go to the depot if it is not too far out of our way. */ |
3532 /* Only go to the depot if it is not too far out of our way. */ |
3516 if (tfdd.best_length == (uint)-1 || tfdd.best_length > MAX_ACCEPTABLE_DEPOT_DIST) { |
3533 if (tfdd.best_length == (uint)-1 || tfdd.best_length > MAX_ACCEPTABLE_DEPOT_DIST) { |
3517 if (v->current_order.type == OT_GOTO_DEPOT) { |
3534 if (v->current_order.type == OT_GOTO_DEPOT) { |
3518 /* If we were already heading for a depot but it has |
3535 /* If we were already heading for a depot but it has |