src/train_cmd.cpp
changeset 9321 61fd5b6e27ce
parent 9297 1cb8d7bbdc8a
child 9354 845e07db4549
equal deleted inserted replaced
9320:4e17d11b92e4 9321:61fd5b6e27ce
  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 */
  3676 					} else {
  3676 					} else {
  3677 						/* we got a front car and no rear cars. We will fake this one for forget that it should have been multiheaded */
  3677 						/* we got a front car and no rear cars. We will fake this one for forget that it should have been multiheaded */
  3678 						ClearMultiheaded(u);
  3678 						ClearMultiheaded(u);
  3679 					}
  3679 					}
  3680 				}
  3680 				}
  3681 			} END_ENUM_WAGONS(u)
  3681 			}
  3682 		}
  3682 		}
  3683 	}
  3683 	}
  3684 }
  3684 }
  3685 
  3685 
  3686 /**
  3686 /**
  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 */
  3738 							SetTrainWagon(u);
  3736 							SetTrainWagon(u);
  3739 							SetFreeWagon(u);
  3737 							SetFreeWagon(u);
  3740 							break;
  3738 							break;
  3741 						default: NOT_REACHED(); break;
  3739 						default: NOT_REACHED(); break;
  3742 					}
  3740 					}
  3743 				} END_ENUM_WAGONS(u)
  3741 				}
  3744 			}
  3742 			}
  3745 		}
  3743 		}
  3746 	}
  3744 	}
  3747 }
  3745 }