From 7d9a970c5cd6d83e3562054c399f72826b128184 Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 14 Mar 2010 14:01:53 +0000 Subject: (svn r19417) -Codechange: More code style, move variable declarations to their first use. --- src/autoreplace_cmd.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index bce3f1ea5..e4caba619 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -134,18 +134,12 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai */ static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, EngineID engine_type) { - const Order *o; - const Vehicle *u; uint32 union_refit_mask_a = GetUnionOfArticulatedRefitMasks(v->engine_type, false); uint32 union_refit_mask_b = GetUnionOfArticulatedRefitMasks(engine_type, false); - if (v->type == VEH_TRAIN) { - u = v->First(); - } else { - u = v; - } - + const Order *o; + const Vehicle *u = (v->type == VEH_TRAIN) ? v->First() : v; FOR_VEHICLE_ORDERS(u, o) { if (!o->IsRefit()) continue; CargoID cargo_type = o->GetRefitCargo(); @@ -168,12 +162,12 @@ static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, EngineID engine_ty */ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool part_of_chain) { - CargoID cargo_type; uint32 available_cargo_types, union_mask; GetArticulatedRefitMasks(engine_type, true, &union_mask, &available_cargo_types); if (union_mask == 0) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity + CargoID cargo_type; if (IsArticulatedVehicleCarryingDifferentCargos(v, &cargo_type)) return CT_INVALID; // We cannot refit to mixed cargos in an automated way if (cargo_type == CT_INVALID) { @@ -622,9 +616,6 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon */ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0); - bool nothing_to_do = true; - Vehicle *v = Vehicle::GetIfValid(p1); if (v == NULL) return CMD_ERROR; @@ -656,6 +647,9 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1 w = (!free_wagon && w->type == VEH_TRAIN ? Train::From(w)->GetNextUnit() : NULL); } + CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0); + bool nothing_to_do = true; + if (any_replacements) { bool was_stopped = free_wagon || ((v->vehstatus & VS_STOPPED) != 0); -- cgit v1.2.3-54-g00ecf