2805 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
2805 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
2806 } |
2806 } |
2807 |
2807 |
2808 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
2808 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
2809 |
2809 |
2810 BEGIN_ENUM_WAGONS(v) |
2810 for (; v != NULL; v = v->Next()) { |
2811 v->vehstatus |= VS_CRASHED; |
2811 v->vehstatus |= VS_CRASHED; |
2812 MarkSingleVehicleDirty(v); |
2812 MarkSingleVehicleDirty(v); |
2813 END_ENUM_WAGONS(v) |
2813 } |
2814 |
2814 |
2815 /* must be updated after the train has been marked crashed */ |
2815 /* must be updated after the train has been marked crashed */ |
2816 if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing); |
2816 if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing); |
2817 } |
2817 } |
2818 |
2818 |
2819 static uint CountPassengersInTrain(const Vehicle *v) |
2819 static uint CountPassengersInTrain(const Vehicle *v) |
2820 { |
2820 { |
2821 uint num = 0; |
2821 uint num = 0; |
2822 BEGIN_ENUM_WAGONS(v) |
2822 |
|
2823 for (; v != NULL; v = v->Next()) { |
2823 if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) num += v->cargo.Count(); |
2824 if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) num += v->cargo.Count(); |
2824 END_ENUM_WAGONS(v) |
2825 } |
|
2826 |
2825 return num; |
2827 return num; |
2826 } |
2828 } |
2827 |
2829 |
2828 struct TrainCollideChecker { |
2830 struct TrainCollideChecker { |
2829 Vehicle *v; ///< vehicle we are testing for collision |
2831 Vehicle *v; ///< vehicle we are testing for collision |
3649 } |
3651 } |
3650 } |
3652 } |
3651 |
3653 |
3652 FOR_ALL_VEHICLES(v) { |
3654 FOR_ALL_VEHICLES(v) { |
3653 if (v->type == VEH_TRAIN && IsFrontEngine(v)) { |
3655 if (v->type == VEH_TRAIN && IsFrontEngine(v)) { |
3654 Vehicle *u = v; |
3656 for (Vehicle *u = v; u != NULL; u = u->Next()) { |
3655 |
|
3656 BEGIN_ENUM_WAGONS(u) { |
|
3657 if (u->u.rail.other_multiheaded_part != NULL) continue; // we already linked this one |
3657 if (u->u.rail.other_multiheaded_part != NULL) continue; // we already linked this one |
3658 |
3658 |
3659 if (IsMultiheaded(u)) { |
3659 if (IsMultiheaded(u)) { |
3660 if (!IsTrainEngine(u)) { |
3660 if (!IsTrainEngine(u)) { |
3661 /* we got a rear car without a front car. We will convert it to a front one */ |
3661 /* we got a rear car without a front car. We will convert it to a front one */ |
3697 } |
3697 } |
3698 |
3698 |
3699 FOR_ALL_VEHICLES(v) { |
3699 FOR_ALL_VEHICLES(v) { |
3700 if (v->type == VEH_TRAIN) { |
3700 if (v->type == VEH_TRAIN) { |
3701 if (HasBit(v->subtype, 7) && ((v->subtype & ~0x80) == 0 || (v->subtype & ~0x80) == 4)) { |
3701 if (HasBit(v->subtype, 7) && ((v->subtype & ~0x80) == 0 || (v->subtype & ~0x80) == 4)) { |
3702 Vehicle *u = v; |
3702 for (Vehicle *u = v; u != NULL; u = u->Next()) { |
3703 |
|
3704 BEGIN_ENUM_WAGONS(u) { |
|
3705 const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); |
3703 const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); |
3706 |
3704 |
3707 ClrBit(u->subtype, 7); |
3705 ClrBit(u->subtype, 7); |
3708 switch (u->subtype) { |
3706 switch (u->subtype) { |
3709 case 0: /* TS_Front_Engine */ |
3707 case 0: /* TS_Front_Engine */ |