Fix #416: Division by zero for trains of 0 mass
In maximum achievable speed estimator
This commit is contained in:
@@ -225,6 +225,6 @@ short DeleteTemplateReplacementsByGroupID(GroupID);
|
||||
|
||||
void ReindexTemplateReplacements();
|
||||
|
||||
int GetTemplateVehicleEstimatedMaxAchievableSpeed(const TemplateVehicle *tv, const int mass, const int speed_cap);
|
||||
int GetTemplateVehicleEstimatedMaxAchievableSpeed(const TemplateVehicle *tv, int mass, const int speed_cap);
|
||||
|
||||
#endif /* TEMPLATE_VEH_H */
|
||||
|
@@ -502,11 +502,13 @@ void UpdateAllTemplateVehicleImages()
|
||||
_template_vehicle_images_valid = true;
|
||||
}
|
||||
|
||||
int GetTemplateVehicleEstimatedMaxAchievableSpeed(const TemplateVehicle *tv, const int mass, const int speed_cap)
|
||||
int GetTemplateVehicleEstimatedMaxAchievableSpeed(const TemplateVehicle *tv, int mass, const int speed_cap)
|
||||
{
|
||||
int max_speed = 0;
|
||||
int acceleration;
|
||||
|
||||
if (mass < 1) mass = 1;
|
||||
|
||||
do
|
||||
{
|
||||
max_speed++;
|
||||
|
@@ -520,6 +520,6 @@ inline int GetTileMarginInFrontOfTrain(const Train *v)
|
||||
int GetTrainStopLocation(StationID station_id, TileIndex tile, Train *v, bool update_train_state, int *station_ahead, int *station_length);
|
||||
|
||||
int GetTrainRealisticAccelerationAtSpeed(const int speed, const int mass, const uint32 cached_power, const uint32 max_te, const uint32 air_drag, const RailType railtype);
|
||||
int GetTrainEstimatedMaxAchievableSpeed(const Train *train, const int mass, const int speed_cap);
|
||||
int GetTrainEstimatedMaxAchievableSpeed(const Train *train, int mass, const int speed_cap);
|
||||
|
||||
#endif /* TRAIN_H */
|
||||
|
@@ -7320,11 +7320,13 @@ int GetTrainRealisticAccelerationAtSpeed(const int speed, const int mass, const
|
||||
return acceleration;
|
||||
}
|
||||
|
||||
int GetTrainEstimatedMaxAchievableSpeed(const Train *train, const int mass, const int speed_cap)
|
||||
int GetTrainEstimatedMaxAchievableSpeed(const Train *train, int mass, const int speed_cap)
|
||||
{
|
||||
int max_speed = 0;
|
||||
int acceleration;
|
||||
|
||||
if (mass < 1) mass = 1;
|
||||
|
||||
do
|
||||
{
|
||||
max_speed++;
|
||||
|
Reference in New Issue
Block a user