summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-12-20 15:08:20 +0000
committerfrosch <frosch@openttd.org>2009-12-20 15:08:20 +0000
commit4434422c1168a2ccbdbe41abea1b59eeef3c2887 (patch)
tree2536cc16c10553b5118580e85678d5b0f2d45c0c /src
parentee3a44e74f5f24fce5f0d1a975d38453b417201b (diff)
downloadopenttd-4434422c1168a2ccbdbe41abea1b59eeef3c2887.tar.xz
(svn r18568) -Codechange: Bail out early.
Diffstat (limited to 'src')
-rw-r--r--src/vehicle.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 7ae9f9ed3..b89d85554 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -118,26 +118,25 @@ bool Vehicle::NeedsServicing() const
Money needed_money = c->settings.engine_renew_money;
if (needed_money > c->money) return false;
- const Vehicle *v = this;
- do {
+ for (const Vehicle *v = this; v != NULL; v = (v->type == VEH_TRAIN) ? Train::From(v)->GetNextUnit() : NULL) {
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);
+ if (new_engine == INVALID_ENGINE || !HasBit(Engine::Get(new_engine)->company_avail, v->owner)) continue;
+
+ /* Check refittability */
+ CargoID cargo_type = CT_INVALID;
+ if (IsArticulatedVehicleCarryingDifferentCargos(v, &cargo_type) || cargo_type == CT_INVALID ||
+ !HasBit(GetIntersectionOfArticulatedRefitMasks(new_engine, true), cargo_type)) continue;
+
+ /* 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) return false;
+ }
- return pending_replace && needed_money <= c->money;
+ return pending_replace;
}
bool Vehicle::NeedsAutomaticServicing() const