mirror of https://github.com/OpenTTD/OpenTTD
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
parent
a62f16c86d
commit
7ea108224b
|
@ -45,6 +45,7 @@
|
||||||
#include "network/network.h"
|
#include "network/network.h"
|
||||||
#include "core/pool_func.hpp"
|
#include "core/pool_func.hpp"
|
||||||
#include "economy_base.h"
|
#include "economy_base.h"
|
||||||
|
#include "articulated_vehicles.h"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
@ -96,7 +97,8 @@ bool Vehicle::NeedsServicing() const
|
||||||
if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false;
|
if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false;
|
||||||
|
|
||||||
/* Are we ready for the next service cycle? */
|
/* Are we ready for the next service cycle? */
|
||||||
if (Company::Get(this->owner)->settings.vehicle.servint_ispercent ?
|
const Company *c = Company::Get(this->owner);
|
||||||
|
if (c->settings.vehicle.servint_ispercent ?
|
||||||
(this->reliability >= Engine::Get(this->engine_type)->reliability * (100 - this->service_interval) / 100) :
|
(this->reliability >= Engine::Get(this->engine_type)->reliability * (100 - this->service_interval) / 100) :
|
||||||
(this->date_of_last_service + this->service_interval >= _date)) {
|
(this->date_of_last_service + this->service_interval >= _date)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -109,9 +111,33 @@ bool Vehicle::NeedsServicing() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off.
|
/* Test whether there is some pending autoreplace.
|
||||||
* Note: If servicing is enabled, we postpone replacement till next service. */
|
* Note: We do this after the service-interval test.
|
||||||
return EngineHasReplacementForCompany(Company::Get(this->owner), this->engine_type, this->group_id);
|
* There are a lot more reasons for autoreplace to fail than we can test here reasonably. */
|
||||||
|
bool pending_replace = false;
|
||||||
|
Money needed_money = c->settings.engine_renew_money;
|
||||||
|
if (needed_money > c->money) return false;
|
||||||
|
|
||||||
|
const Vehicle *v = this;
|
||||||
|
do {
|
||||||
|
EngineID new_engine = EngineReplacementForCompany(c, v->engine_type, v->group_id);
|
||||||
|
/* Check engine availability */
|
||||||
|
if (new_engine != INVALID_ENGINE && HasBit(Engine::Get(new_engine)->company_avail, v->owner)) {
|
||||||
|
/* Check refittability */
|
||||||
|
CargoID cargo_type = CT_INVALID;
|
||||||
|
if (!IsArticulatedVehicleCarryingDifferentCargos(v, &cargo_type) && cargo_type != CT_INVALID &&
|
||||||
|
HasBit(GetIntersectionOfArticulatedRefitMasks(new_engine, true), cargo_type)) {
|
||||||
|
/* Check money.
|
||||||
|
* We want 2*(the price of the new vehicle) without looking at the value of the vehicle we are going to sell. */
|
||||||
|
pending_replace = true;
|
||||||
|
needed_money += 2 * Engine::Get(new_engine)->GetCost();
|
||||||
|
if (needed_money > c->money) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v = (v->type == VEH_TRAIN) ? Train::From(v)->GetNextUnit() : NULL;
|
||||||
|
} while (v != NULL);
|
||||||
|
|
||||||
|
return pending_replace && needed_money <= c->money;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vehicle::NeedsAutomaticServicing() const
|
bool Vehicle::NeedsAutomaticServicing() const
|
||||||
|
|
Loading…
Reference in New Issue