Merge branch 'improved_breakdowns' into improved_breakdowns-sx
This commit is contained in:
		@@ -148,6 +148,17 @@ void CheckBreakdownFlags(Train *v)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint16 GetTrainVehicleMaxSpeed(const Train *u, const RailVehicleInfo *rvi_u, const Train *front)
 | 
			
		||||
{
 | 
			
		||||
	uint16 speed = GetVehicleProperty(u, PROP_TRAIN_SPEED, rvi_u->max_speed);
 | 
			
		||||
	if (HasBit(u->flags, VRF_NEED_REPAIR) && front->IsFrontEngine()) {
 | 
			
		||||
		for (uint i = 0; i < u->critical_breakdown_count; i++) {
 | 
			
		||||
			speed = min(speed - (speed / (front->tcache.cached_num_engines + 2)) + 1, speed);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return speed;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Recalculates the cached stuff of a train. Should be called each time a vehicle is added
 | 
			
		||||
 * to/removed from the chain, and when the game is loaded.
 | 
			
		||||
@@ -238,12 +249,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
 | 
			
		||||
 | 
			
		||||
			/* max speed is the minimum of the speed limits of all vehicles in the consist */
 | 
			
		||||
			if ((rvi_u->railveh_type != RAILVEH_WAGON || _settings_game.vehicle.wagon_speed_limits) && !UsesWagonOverride(u)) {
 | 
			
		||||
				uint16 speed = GetVehicleProperty(u, PROP_TRAIN_SPEED, rvi_u->max_speed);
 | 
			
		||||
				if (HasBit(u->flags, VRF_NEED_REPAIR) && this->IsFrontEngine()) {
 | 
			
		||||
					for (uint i = 0; i < u->critical_breakdown_count; i++) {
 | 
			
		||||
						speed = min(speed - (speed / (this->tcache.cached_num_engines + 2)) + 1, speed);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				uint16 speed = GetTrainVehicleMaxSpeed(u, rvi_u, this);
 | 
			
		||||
				if (speed != 0) max_speed = min(speed, max_speed);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,8 @@
 | 
			
		||||
 | 
			
		||||
#include "safeguards.h"
 | 
			
		||||
 | 
			
		||||
uint16 GetTrainVehicleMaxSpeed(const Train *u, const RailVehicleInfo *rvi_u, const Train *front);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Callback for building wagons.
 | 
			
		||||
 * @param result The result of the command.
 | 
			
		||||
@@ -267,7 +269,7 @@ static void TrainDetailsInfoTab(const Train *v, int left, int right, int y, byte
 | 
			
		||||
				} else {
 | 
			
		||||
					if (HasBit(v->flags, VRF_NEED_REPAIR)) {
 | 
			
		||||
						SetDParam(0, STR_NEED_REPAIR);
 | 
			
		||||
						SetDParam(1, v->vcache.cached_max_speed);
 | 
			
		||||
						SetDParam(1, GetTrainVehicleMaxSpeed(v, &(v->GetEngine()->u.rail), v->First()));
 | 
			
		||||
					} else {
 | 
			
		||||
						SetDParam(0, STR_RUNNING);
 | 
			
		||||
					}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user