1
0
Fork 0

Codechange: Reorder code in autoreplace vehicles.

pull/8480/head
J0anJosep 2021-01-09 17:22:46 +01:00
parent 8a9a627577
commit 6f20beb49a
1 changed files with 27 additions and 26 deletions

View File

@ -28,6 +28,7 @@
#include "order_cmd.h"
#include "train_cmd.h"
#include "vehicle_cmd.h"
#include "depot_map.h"
#include "table/strings.h"
@ -777,11 +778,10 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlag flags, VehicleID veh_id)
any_replacements |= (e != INVALID_ENGINE);
w = (!free_wagon && w->type == VEH_TRAIN ? Train::From(w)->GetNextUnit() : nullptr);
}
if (!any_replacements) return_cmd_error(STR_ERROR_AUTOREPLACE_NOTHING_TO_DO);
CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, (Money)0);
bool nothing_to_do = true;
if (any_replacements) {
bool was_stopped = free_wagon || ((v->vehstatus & VS_STOPPED) != 0);
/* Stop the vehicle */
@ -808,14 +808,15 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlag flags, VehicleID veh_id)
} else {
ret = ReplaceChain(&v, flags, wagon_removal, &nothing_to_do);
}
assert(ret.Succeeded() && ret.GetCost() == cost.GetCost());
assert(ret.Succeeded());
assert(ret.GetCost() == cost.GetCost());
}
/* Restart the vehicle */
if (!was_stopped) cost.AddCost(DoCmdStartStopVehicle(v, false));
}
if (cost.Succeeded() && nothing_to_do) cost = CommandCost(STR_ERROR_AUTOREPLACE_NOTHING_TO_DO);
assert(cost.Failed() || !nothing_to_do);
return cost;
}